문제

나는 모두 같은 크기의 세 가지 배열을 가지고 있습니다.

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

b가 true 인 지수에 해당하는 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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top