I'm relatively new to Scilab and I would like to find the indices of a number in my matrix.
I have defined my number as maximal deformation (MaxEYY
) and on displaying it, it is correct (I can double check in my *.csv file). However, when I want to know exactly where this number lies in my matrix using the find
command, only (1,1) is returned, but I know for a fact that this number is located at (4,8).
My matrix is not huge (4x18) and I know that this number only occurs once. On opening the *.csv file, I removed the headers so there is no text.
Can anyone help me with this?
N=csvRead("file.csv",",",".",[],[],[],[],1)
EYY=N(:,8);
MaxEYY=max(EYY);
MinEYY=min(EYY);
[a,b]=find(MaxEYY);
disp([a,b]);
First, you need to understand how find()
works: it looks for values of true or false in a matrix. So if you want to find a certain value in it, you should do find(value == matrix)
.
Then, notice that in your code, you are applying find()
to MaxEYY
, which is a single value, that is, a scalar, a 1-by-1 matrix. When you do that, you can only get (1,1) or []
as results.
Now, combining these two informations, this what you should've done:
[a, b] = find(EYY == MaxEYY);
Also, there is a quicker way to get this indices: max()
can also return the indices of the maximum value by doing
[MaxEYY, inds] = max(EYY);
And the same goes for min()
.