How can i find the column number in an array?

1 回表示 (過去 30 日間)
Priyanka Bhasker
Priyanka Bhasker 2019 年 1 月 20 日
コメント済み: per isakson 2019 年 1 月 21 日
I have imported data from a .txt file into matlab. The question is to find the column number of the column with the highest average. How do I find the column number that corresponds to the highest average value?

回答 (1 件)

per isakson
per isakson 2019 年 1 月 20 日
編集済み: per isakson 2019 年 1 月 20 日
Try this
M = rand( 6 ); % Sample data
[~,ixc] = max(mean( M, 1 ));
  5 件のコメント
Image Analyst
Image Analyst 2019 年 1 月 21 日
Well as long as the matrix is not all null or all nan, there will be a max, and it will occur at one or more columns. Super robust code would check for the "all null" or "all nan" situation.
per isakson
per isakson 2019 年 1 月 21 日
Thank you for your comments. I just learned that both mean and max have nanflag the deault values of which are different.
"all null", but there is no null in Matlab?

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by