Question

J'ai trois tableaux, la même taille:

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 leur assigner 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.
Était-ce utile?

La solution

Vous devez utiliser la fonction num2cell pour convertir la main droite un côté à un réseau de cellules avant de l'affecter à xout:

xout(b) = num2cell(xin(b));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top