CELL2MAT does not support cell arrays containing cell arrays or objects.
Show older comments

hello guys.Can you understand Chinese?The sentence in blue means that "CELL2MAT does not support cell arrays containing cell arrays or objects".I never see any error like this.I translated it into English by Google Translator.So it may be not accurate.Do anyone experience this error.Could you please tell me how to do?By the way,my MATLAB version is R2019b,the code is earlier.So i think whether the old version and the new version are incompatible.I think the code itself don't have grammatical errors.Thank you for your answer!
12 Comments
Walter Roberson
on 22 Feb 2020
We will need to see the code.
Berney Li
on 22 Feb 2020
Walter Roberson
on 22 Feb 2020
The problem appears to be at line 11
haxes = cell2mat(struct2cell(ax));
I would not have expected that line to ever work. It is wrong in multiple ways.
Replacement code:
if isstruct(ax)
ax_cell = struct2cell(ax);
haxes = vertcat(ax_cell{:});
else
haxes = ax;
end
Berney Li
on 23 Feb 2020
Berney Li
on 23 Feb 2020
Walter Roberson
on 23 Feb 2020
Put in a line of code that asks it to celldisp(ax_cell) and show us the results
Berney Li
on 23 Feb 2020
Walter Roberson
on 23 Feb 2020
No, I mean like
if isstruct(ax)
ax_cell = struct2cell(ax);
cell_disp(ax_cell);
haxes = vertcat(ax_cell{:});
else
haxes = ax;
end
This is not expected to fix the problem: this is expected to display output that you will copy and paste here and that will help me diagnose the problem.
Berney Li
on 24 Feb 2020
Berney Li
on 24 Feb 2020
Berney Li
on 8 Mar 2020
Walter Roberson
on 9 Mar 2020
That model was designed for MATLAB R13SP1, which was from 2003. It is not surprising that it does not work in current releases.
Answers (1)
Indeed cell2mat does not support converting a cell array containing objects into a matrix. It looks like your cell array contains axes handles. Prior to R2014b axes handles used to be plain numbers so indeed you could convert a cell array of axes handles to a matrix. From R2014b, axes handles are objects and the error would appear.
Without knowing the exact details of what is in your cell array (shape and size) it's not easy to tell you how to solve the problem. Hence why Walter asked you to run the celldisp, so we could see what's in there.
Assuming that each cell contains a single axes handle, or row vectors of axes handles, then:
axes_mat = [ax_cell{:}];
If the cells contain column vectors/of axes handles:
axes_mat = vertcat(ax_cell{:});
If they contain 2D or ND matrix, it will be more complicated.
edit: following the output of celldisp being shown:
Since the cell array contains scalar axes handles, any of the above would work.
1 Comment
Walter Roberson
on 23 Feb 2020
Oh, good point about the handles being numeric before!
Categories
Find more on Programming 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!



