replacing any value in a matrix

2 ビュー (過去 30 日間)
Muhammad Haziq
Muhammad Haziq 2019 年 1 月 16 日
コメント済み: Muhammad Haziq 2019 年 1 月 16 日
I have 3x7 matrix. I want to replace any number by 10 (which is greater than 4). I write this code but its not working. Can any body help me ?
A=[1,2,5,2,3,4,2; 4,2,1,5,3,2,3; 1,4,2,3,2,2,1];
% 1 2 5 2 3 4 2
% 4 2 1 5 3 2 3
% 1 4 2 3 2 2 1
for k=1:1:3
if A(k,4)>4
A(k,4)==10
end
end
expected result:
% 1 2 5 2 3 4 2
% 4 2 1 10 3 2 3
% 1 4 2 3 2 2 1
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 1 月 16 日
A(k,4)==10
That is a comparison, not an assignment. Assignment uses =

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 16 日
A(A>4) = 10;
No loop needed.
  1 件のコメント
Muhammad Haziq
Muhammad Haziq 2019 年 1 月 16 日
Thanks

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by