Pergunta

Eu tenho três matrizes, todos do mesmo tamanho:

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

Como posso tirar os elementos de xin que correspondem aos índices de onde b é verdadeiro, e atribuí-los aos lugares correspondentes no 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.
Foi útil?

Solução

Você deve usar a função num2cell para converter a mão direita lado a uma matriz de célula antes de atribuí-la a xout:

xout(b) = num2cell(xin(b));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top