フィルターのクリア

How can I print the positions that a value occur in a row array?

12 ビュー (過去 30 日間)
Andrew Padilla
Andrew Padilla 2018 年 9 月 15 日
編集済み: Andrew Padilla 2018 年 9 月 15 日
If I have the matrix
A = [0, 2, 2, 6, 4, 3, 10]
and
Minimum = min(A)
How do I print the column positions that each minimum value occurs at? The statement below works only if there is only one minimum value present.
Assume X is the value of the position of the minimum value.
How can I print the positions if the minimum value occurs more than once?
fprintf('\nMinimum Temperature [degrees C]: %f (at position(s): %f)',Minimum, X);

採用された回答

Image Analyst
Image Analyst 2018 年 9 月 15 日
Try this:
X = randi(9, 1, 40)
minTemperature = min(X);
indexes = find(X == min(X));
fprintf('Minimum Temperature of %.3f degrees C:\n', minTemperature);
fprintf(' at position: %d\n', indexes);
Sample results:
X =
Columns 1 through 21
2 7 5 5 8 8 5 3 2 8 9 9 6 1 1 2 1 7 2 6 8
Columns 22 through 40
6 4 8 3 3 8 5 3 7 2 9 3 1 1 7 8 7 7 9
Minimum Temperature of 1.000 degrees C:
at position: 14
at position: 15
at position: 17
at position: 34
at position: 35
  1 件のコメント
Andrew Padilla
Andrew Padilla 2018 年 9 月 15 日
編集済み: Andrew Padilla 2018 年 9 月 15 日
I receive the following errors when running the code:
Index exceeds array bounds.
Array indices must be positive integers or logical values.
UPDATE:
I have fixed the issue. I kept the code that I was originally using except I separated the print statements into two like you did in the code you provided above. Thank you.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by