Clear Filters
Clear Filters

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

3 views (last 30 days)
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

Answers (2)

James Tursa
James Tursa on 30 Jul 2017
Edited: James Tursa on 30 Jul 2017
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 Comment
Payjay
Payjay on 30 Jul 2017
I am sorry, the error occured because the first two elements X0{1 and 2} were empty.. this was a stupid question! Thanks anyways!

Sign in to comment.


Image Analyst
Image Analyst on 30 Jul 2017
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.

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!