Matrix value change with conditions (x=y*(mask==1))

4 views (last 30 days)
I have two matrix x,y and mask.
x = [1,1,1,1;...
2,2,2,2;...
3,3,3,3;...
4,4,4,4];
y = [5,5,5,5;...
5,5,2,5;...
5,5,5,5;...
5,5,5,5];
mask = [0,0,0,0;...
1,1,1,1;...
0,0,0,0;...
1,1,1,1];
When try perform this:
x=y*(mask==1)
Result is:
x =
10 10 10 10
10 10 10 10
10 10 10 10
10 10 10 10
Why?

Accepted Answer

madhan ravi
madhan ravi on 24 May 2019
Edited: madhan ravi on 24 May 2019
(* performs matrix multiplication) perhaps you needed .* element wise multiplication
  5 Comments
madhan ravi
madhan ravi on 24 May 2019
Edited: madhan ravi on 24 May 2019
Show how your expected result should look like with an example.
Perhaps you wanted to do:
x(mask==1)=y(mask==1)

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!