How can I change all the elements in a matrix with value1 to a new value2?
1 回表示 (過去 30 日間)
古いコメントを表示
I have a 78X78 binary matrix. How can I change all the 0s to -1s?
0 件のコメント
回答 (2 件)
Torsten K
2020 年 10 月 15 日
How about this?
m = randi([0,1],78) % 78x78 matrix with random integers in the interval 0..1
m(m==0)=-1 % Substitute all 0's b -1's
Best regards
Torsten
0 件のコメント
Ameer Hamza
2020 年 10 月 15 日
編集済み: Ameer Hamza
2020 年 10 月 15 日
Another approach
M; % 78x78 matrix
M_new = 2*M-1;
This will be faster as compared to the indexing approach.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!