How to swap array element from two arrays conditionally
显示 更早的评论
I'm looking to plot a matrix using data from two arrays. If the second array has a number which is not zero in an element, this element is moved into the first array. I have seen how this might be done using deal(), but I would like to avoid using a loop with if statement for performance reasons. Is there a convenient way of doing this?
An example of this is follows, with arrays A, B and C ( the result);

采纳的回答
更多回答(1 个)
JESUS DAVID ARIZA ROYETH
2019-12-4
C=A;
C(B~=0)=B(B~=0)
also could help you:
C=max(A,B)
类别
在 帮助中心 和 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!