Cell contents reference from a non-cell array object, why?

Hello there, ellipse_l is a cell array and each element is also a cell array with a certain number of structs in it. Why do I get the error shown in the headline?
Greets!
X0_r = cell(length, 1);
for i = 1:(numel(find(~cellfun(@isempty, ellipse_l))))
for j = 1:(numel(find(~cellfun(@isempty, ellipse_l))))
X0_r{i}{j} = ellipse_r{i}{j}.X0;
end
end

답변 (2개)

James Tursa
James Tursa 2017년 7월 30일
편집: James Tursa 2017년 7월 30일
As written, X0_r is a cell array, but the elements of this cell array are NULL (empty) since nothing has been put into it yet. So in this expression:
X0_r{i}{j}
you are trying to access the j'th element of a cell array, but there is no such cell array in that spot. That is, X0_r is a cell array but X0_r{i} is not a cell array since it is NULL (empty). So that {j} part attempts to access X0_r{i} as if it were a cell array which it isn't.

댓글 수: 1

I am sorry, the error occured because the first two elements X0{1 and 2} were empty.. this was a stupid question! Thanks anyways!

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2017년 7월 30일
length is is a built in function, so this doesn't make sense
X0_r = cell(length, 1);
Try this instead:
X0_r = cell(size(ellipse_l));
celldisp(ellipse_1); % Display it to verify it looks good.
celldisp(X0_r); % Display it to verify it's blank and the same size as ellipse_l.

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2017년 7월 30일

편집:

2017년 7월 30일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by