How to do a simple elementwise logic in a matrix?
1 次查看(过去 30 天)
显示 更早的评论
Let's say I have A=[1 0.5 2; 0.5 1 1; 3 1 0.5];
I need to create a new matrix (with the same size as A) in which elements of A that are less than one are multiplied by 10 and those elements larger than one are multiplied by 100. I know how to do it with a 'for', but any better idea?
Thanks,
采纳的回答
the cyclist
2013-12-19
You're so close!
(A<=1).*(A.*10) + (A>1).*(A.*100)
(You wrote 100 in your question, but used 200 in your code.)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Array Geometries and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!