Min of each row of a matrix and their indexes
10 views (last 30 days)
Show older comments
I have the topography data in which I introduced X, Y, Z as follows. How can I find min for each row of Z data and find their X and Y value?

0 Comments
Accepted Answer
Andrei Bobrov
on 21 Aug 2016
X=[11 13 15]
Y=[43 45 47]
Z = [27 25 21;35 38 37 ;42 47 49]
[~,ii] = min(Z,[],2)
out = [X(ii)',Y(:)]
0 Comments
More Answers (1)
Geoff Hayes
on 21 Aug 2016
Babak - if you want to find the minimum of each row of Z then use min as follows
>> Z = [27 25 21; 35 38 37; 42 47 49];
>> min(Z,[],2)
ans =
21
35
42
To get the index of each of the above then do
>> [minValues, minIndices] = min(Z,[],2)
minValues =
21
35
42
minIndices =
3
1
1
Presumably, your x and y coordinates for these values would then be
X(minIndices)
Y(minIndices)
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!