Matrix manipulation problem under MATLAB

2 visualizzazioni (ultimi 30 giorni)
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}

Risposta accettata

Stephen23
Stephen23 il 8 Nov 2018
Modificato: Stephen23 il 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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by