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!