how to find max of 1000 values which are rows,i wrote a code it showed just one value and index that is not the max

1 回表示 (過去 30 日間)
filename='realtimevalues.xlsx';
num=xlsread(filename);
y=filename(1,:);
[val idx]=max(y(:))

採用された回答

Image Analyst
Image Analyst 2016 年 2 月 17 日
num is a 2D array of numbers, or it may be depending on how your data area arranged in the workbook. y is the first character of filename, which is 'r'. I think you want
y = num(1, :); % Extract first row only.
  2 件のコメント
Titus Edelhofer
Titus Edelhofer 2016 年 2 月 17 日
Hmm, in the original post it's
y = filename(1,:)
?
y=num(:)
or
y=num(1,:)
both should give reasonable results, depending of what is searched for ...

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

その他の回答 (1 件)

Titus Edelhofer
Titus Edelhofer 2016 年 2 月 17 日
Hi Shina,
what exactly is the question: you think val is not the maximum of y? I don't see how this can happen ... Or are you interested in all indices where y is taking it's maximum? In this case you could do something like
idx = find(y(:)==max(y(:)));
Note though, that this is sensitive to floating point accuracy, so if you have
y = [1 1.0000000001 1]
this would find only idx=2.
Titus
  1 件のコメント
shina mokhtari
shina mokhtari 2016 年 2 月 17 日
you know i think the problem is i have 1000 values,and it show the wrong value and also index,for example when i write this code it show value 120 and index 16 wich is not true

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by