我有三个阵列,所有具有相同的尺寸:

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

如何采取对应于其中b为真索引鑫的元件,并且将它们在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.
有帮助吗?

解决方案

您应该使用功能 num2cell 右手转换侧到单元阵列分配给它之前xout

xout(b) = num2cell(xin(b));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top