Getting error when asking from max and min for negative values.

21 ビュー (過去 30 日間)
Yasmin Samy
Yasmin Samy 2017 年 12 月 27 日
コメント済み: Yasmin Samy 2017 年 12 月 27 日
I have two vector of negative numbers (log values). The first is fine as it has a postive max value and a negative min. But i get an error for the second vector (which has its max and min as negative numbers) when i ask for max or min. What is another option to get these two values??
error: Subscript indices must either be real positive integers or logicals.
  2 件のコメント
Rik
Rik 2017 年 12 月 27 日
What code are you using? Are you using the min and max functions? The error sounds like you aren't.
Yasmin Samy
Yasmin Samy 2017 年 12 月 27 日
編集済み: Walter Roberson 2017 年 12 月 27 日
the vector is A, the code lines are:
max=max(A);
min=min(A);

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

採用された回答

Image Analyst
Image Analyst 2017 年 12 月 27 日
Sounds like you may be trying to index into the array using the min or max value instead of the index:
mn = min(data);
minValue = data(mn);
Don't do that. Use both values if you want to get the index. A better way:
[minValue, indexOfMin] = min(data);
[maxValue, indexOfMax] = max(data);
Or you may have used min for the variable
min = min(data); % Horrible idea
in which case when you came along and tried to do it again, it would have used your min array (a vector is data was a 2-D array) as indexes into your newly created min array. min() is no longer the min function if you replaced it with a variable of the same name. So if the min was now an array of column mins because you stored the mins in an array called min, then doing min(data) will throw that error if any elements of data have negative, zero, or floating points (fractional) values.
  1 件のコメント
Yasmin Samy
Yasmin Samy 2017 年 12 月 27 日
Ah!! ok thanks you guys!
You are right. It works now. :)

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 12 月 27 日
Do not name a variable min or max. Also do not name a variable sum . Using any of these variable names is quite likely to run into problems when you later try to use the same name as if it were the MATLAB function.
  2 件のコメント
Yasmin Samy
Yasmin Samy 2017 年 12 月 27 日
Yes you are right. Luckily, its not the cause of my problem. As the vector im having an issue with i used omax and omin as the name of the values for the maximum and min. So it's like omax=max(oA);
Thanks for your comment though.
Yasmin Samy
Yasmin Samy 2017 年 12 月 27 日
Thanks...it seems using it in the first place messed things

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by