Matrix manipulation problem under MATLAB

2 次查看(过去 30 天)
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}

采纳的回答

Stephen23
Stephen23 2018-11-8
编辑:Stephen23 2018-11-8
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by