フィルターのクリア

How do I extract non zero minimum value and its index from a specific row??

1 回表示 (過去 30 日間)
akash sonnad
akash sonnad 2018 年 4 月 20 日
コメント済み: Guillaume 2018 年 4 月 23 日
for ex, C=[0,10,8,9,7;10,0,10,5,6;8,10,0,8,9;9,5,8,0,6;7,6,9,6,0]; i need min value from row 1 greater than zero. How do i get it?
  1 件のコメント
Dennis
Dennis 2018 年 4 月 20 日
編集済み: Dennis 2018 年 4 月 20 日
min(C(C~=0))
find(C,min(C(C~=0)))

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

回答 (1 件)

Guillaume
Guillaume 2018 年 4 月 20 日
編集済み: Guillaume 2018 年 4 月 20 日

If you want the minimum value greater than 1 from all the rows, then simply replace the values below 1 by inf and take the minimum:

C = [0,10,8,9,7;10,0,10,5,6;8,10,0,8,9;9,5,8,0,6;7,6,9,6,0];
tempC = C;
tempC(C < 1) = inf;
[minofrow, whichcolumn] = min(tempC, [], 2)
  4 件のコメント
akash sonnad
akash sonnad 2018 年 4 月 20 日
I mean extracting non zero row minimum from any randow row
Guillaume
Guillaume 2018 年 4 月 23 日

Have you tried the code? It gives you the minimum greater (or equal( than one for each row. You can then use basic indexing to get the row that interest you.

Note that if you want the non-zero minimum instead of minimum greater than 1, then use

tempC(C == 0) = inf;

instead.

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

カテゴリ

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