help how can I find the minimum number and return it's index in each row?

help how can I find the minimum number and return it's index in each row?

1 件のコメント

maha ismail
maha ismail 2014 年 11 月 13 日
I have a matrix not a vector and I need the minimum value except 0 and position of minimum value in each row

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

 採用された回答

Manoj
Manoj 2014 年 11 月 13 日
a=[8,2,3,4,5];
[b,ix]=min(a);
ix gives you the positions and b gives the minimum value

4 件のコメント

maha ismail
maha ismail 2014 年 11 月 13 日
I need to correct this program
Guillaume
Guillaume 2014 年 11 月 13 日
編集済み: Guillaume 2014 年 11 月 13 日
Your question has been answered, so you should accept the answer.
As for your program, it has no comment and you haven't even said what is wrong with it or what it's supposed to do. What are we supposed to correct?
Your program is just a convoluted way of doing
mm = m(:)';
Is that the correction you're looking for?
maha ismail
maha ismail 2014 年 11 月 13 日
sorry dear I have a matrix not a vector I have a positive number and 0 I need to find the minimum value except 0 and I need to return the position of minimum value in each row ..but my program is not run..
maha ismail
maha ismail 2014 年 11 月 13 日
dear manoj thanks alot for help me its a perfect solution but I need another update if the matrix has a zero value and the zero is the smallest value but I don't choose it I need more than zero and the smallest after zero

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

その他の回答 (1 件)

Guillaume
Guillaume 2014 年 11 月 13 日
To find the minimum of a row, use:
min(m, [], 2)
Probably, the simplest way to ignore 0s is to replace them with NaNs before calling min.
m(m == 0) = nan;
[mval, mcol] = min(m, [], 2);

1 件のコメント

maha ismail
maha ismail 2014 年 11 月 13 日
dear Guillaume thanks alot for help me ..it's done

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2014 年 11 月 13 日

コメント済み:

2014 年 11 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by