Matrix manipulation problem under MATLAB

1 Ansicht (letzte 30 Tage)
dakhli mohamed
dakhli mohamed am 8 Nov. 2018
Kommentiert: dakhli mohamed am 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}

Akzeptierte Antwort

Stephen23
Stephen23 am 8 Nov. 2018
Bearbeitet: Stephen23 am 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

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by