Find the number of a row in a matrix that have a minimum value compare to another specific row

1 回表示 (過去 30 日間)
Hello every body
I have a matrix A, I need to find the minimum of row 3 and 4 (for example) on the first column. And I finaly want my code returns the number of the row within the first matrix,
I write this but I got 1 as an output while I want 3.
A=[0 28;28 0;9 26;29 21;10 32;3 26];
[mindistedge,next]=min(A([3 4],1));
Since the minimum of line 3 and 4 is 9 and it is on the third row. But I got the below answer:
mindistedge =
9
next =
1
How can I edit my code to get next=3?
Thanks a lot

採用された回答

Stephen23
Stephen23 2019 年 9 月 24 日
>> A = [0,28;28,0;9,26;29,21;10,32;3,26]
A =
0 28
28 0
9 26
29 21
10 32
3 26
>> vec = [3,4];
>> [~,idx] = min(A(vec,1));
>> vec(idx)
ans = 3
  1 件のコメント
Zarak kh
Zarak kh 2019 年 9 月 24 日
Thanks a lot for your answer, Is there any way to decrease lines of the code ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by