Matrix value change with conditions (x=y*(mask==1))
4 views (last 30 days)
Show older comments
pawel banasiak
on 24 May 2019
Commented: pawel banasiak
on 24 May 2019
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?
0 Comments
Accepted Answer
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
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)
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!