how to change matrix element from zero to 1

2 ビュー (過去 30 日間)
amina shafanejad
amina shafanejad 2015 年 5 月 17 日
コメント済み: Stephen23 2015 年 5 月 17 日
hello i have one matrix 4 by 4 which only it has few zero element how can i say it check the element if less than one then change it to one ?

回答 (1 件)

the cyclist
the cyclist 2015 年 5 月 17 日
If A is your matrix,
A(A<1) = 1
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 5 月 17 日
for K = 1
A = max(A,1);
end
Stephen23
Stephen23 2015 年 5 月 17 日
Why use a loop for this? It is faster and neater using the cyclist's vectorized code.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by