Minimum cell of a matrix

1 回表示 (過去 30 日間)
Ken
Ken 2016 年 10 月 11 日
コメント済み: Walter Roberson 2016 年 10 月 16 日
I am trying to find the minimum-value cell of a matrix. To simplify, I take a 3X3 matrix, I tried this but no luck.
Row1=2;
Col1=2;%This is the mid-cell of the 3X3 Matrix
min=99;
if B(Row1,Col1)~=0
for Row =-1:1:1
for Col==-1:1:1 % this gets the adjacent cells of the 3X3 matrix
if B(Row+Row1, Col+Col1)<min
min=B(Row+Row1,Col+Col1);

回答 (1 件)

Marc Jakobi
Marc Jakobi 2016 年 10 月 11 日
編集済み: Marc Jakobi 2016 年 10 月 11 日
You need to end every loop and if statement with an end keyword
Min=inf;
for Row =1:size(B,1)
for Col==1:size(B,2)
if B(Row, Col)<Min
Min=B(Row,Col);
end
end
end
Is this a homework assignment? If not, you can also just use
m = Min(B(:));
  10 件のコメント
Ken
Ken 2016 年 10 月 15 日
Thanks. My matrix is the subject matrix. block.data is my 3X3 matrix?
Walter Roberson
Walter Roberson 2016 年 10 月 16 日
Yes, block.data would be the 3 x 3 matrix currently being examined.

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

カテゴリ

Help Center および File ExchangeMarine and Underwater Vehicles についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by