I have two matrices and I would like to create a matrix containing the above threshold value of each element of both matrices

1 次查看(过去 30 天)
I have two matrices of the same size and for each element I would like to do the following:
if the value of the element in matrix2 is above the threshold, keep the value
else assign the value of matrix1 to this element.
Is this possible without for loops?

采纳的回答

Matt J
Matt J 2020-6-15
编辑:Matt J 2020-6-15
Is this possible without for loops?
Yes. One way is as follows:
mask=(matrix2>=threshold);
result = matrix2.*mask + matrix1.*(~mask);

更多回答(1 个)

Matt J
Matt J 2020-6-15
Another way,
result=matrix2;
idx=(matrix2<threshold);
result(idx)=matrix1(idx);

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by