フィルターのクリア

Finding indices in a magic 5x5 matrix in which the values are greater than 20?

2 ビュー (過去 30 日間)
Kristopher
Kristopher 2014 年 6 月 17 日
回答済み: Geoff Hayes 2014 年 6 月 17 日
There is a 5x5 matrix, and I am trying to find the values that are greater than 20. Would I use something like >>A=magic(5)
A=1 1 1; 1 1 1; 1 1 1; >>[mx,i]=n>20(A) %return values greater than 20
%I don't currently have access to matlab, therefore I'm writing the code on paper ahead of time.

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 6 月 17 日
While the initialization of the magic A matrix is correct, the code that follows is unclear. Why the second initialization of A? What is n?
The easiest way to find those elements of A that are greater than 20 is to use the find function. In the Command Window, type doc find or help find for details on this function. The first example is similar to yours
A = magic(5);
[rIdcs,cIdcs] = find(A>20);
where rIdcs and cIdcs are the row and column indices respectively of those elements of A that are greater than 20.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by