Min of each row of a matrix and their indexes

조회 수: 10 (최근 30일)
Babak MJ
Babak MJ 2016년 8월 21일
답변: Andrei Bobrov 2016년 8월 21일
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?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 8월 21일
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(:)]

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 8월 21일
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)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by