MATLAB:セル配列へdouble配列からベクトル化の割り当て
-
13-09-2019 - |
質問
私は3つの配列を持っている、すべて同じサイズます:
xout % cell array
xin % numeric array of doubles
b % logical array
どのように私はbが真であるインデックスに対応し、XINの要素を取り、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));
所属していません StackOverflow