Matrix manipulation problem under MATLAB
1 view (last 30 days)
Show older comments
dakhli mohamed
on 8 Nov 2018
Commented: dakhli mohamed
on 8 Nov 2018
hello I have two matrix the first Swapping={1,1,1; 1,5,1; 2,3,4};
and the second C1={59,57,46 4,39,35 8,22,20} I want to display in a third matrix the values of the second matrix that have the same box with the valeus 1 and 0 besides
result matrix={{59,57,46 4,0,35 0,0,0}
0 Comments
Accepted Answer
Stephen23
on 8 Nov 2018
Edited: Stephen23
on 8 Nov 2018
Storing scalar numerics in cell arrays will make your processing pointlessly complex, so I will presume that you actually sensibly store your numeric data in simpler and more efficient numeric arrays. Then your task is easy:
>> Swapping = [1,1,1;1,5,1;2,3,4]
Swapping =
1 1 1
1 5 1
2 3 4
>> C1 = [59,57,46;4,39,35;8,22,20]
C1 =
59 57 46
4 39 35
8 22 20
>> result = C1 .* (Swapping==1)
result =
59 57 46
4 0 35
0 0 0
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!