2009-11-03 9 views
4

J'ai trois tableaux, tous de la même taille:Matlab: Affectation vectorisé de matrice double à matrice de cellules

xout  % cell array 
xin   % numeric array of doubles 
b   % logical array 

Comment puis-je prendre les éléments de xin qui correspondent aux indices où b est vrai, et attribuer les aux endroits correspondants dans xout?

>> xout = {'foo', 'bar', 'baz', 'quux'}; 
>> xin = [1, 2, 3, 4]; 
>> b = (xin ~= 2);  % yields [1 0 1 1] in this case 
>> xout{b}=xin(b); 
??? The right hand side of this assignment has too few values 
to satisfy the left hand side. 

>> xout(b)=xin(b); 
??? Conversion to cell from double is not possible. 

Répondre

5

Vous devez utiliser la fonction NUM2CELL pour convertir le côté droit à un réseau de cellules avant de l'assigner à xout:

xout(b) = num2cell(xin(b)); 
+0

doh! ça marche, merci. –

Questions connexes