MATLAB: How to find the location of the first negative value in a column
MATLABnegative value column vector
For example, if I have a column a=[1;2;-3;4;-5;6]
and I wanted to find the location of the first negative value (1,3), how can I do this?
Thank you for your time!
Best Answer
Like this?
a=[1;2;-3;4;-5;6];
[r,c]=find(a<0,1);
a(r,c)
(if you plan on using matrices as well: note that what is 'first' in a matrix, is defined by the array order, so for matrices this code is equivalent to[r,c]=find(a(:)<0,1);)
Best Answer