CELL2MAT error in version 2015a

1 visualización (últimos 30 días)
curoi
curoi el 15 de Sept. de 2015
Respondida: Kelly Kearney el 15 de Sept. de 2015
I'm currently using a modified version of the ginput2.m function from the code exchange but I'm recieving the following error when I select more than 2 points:
hlastaxes = cell2mat(hlastaxes)
CELL2MAT does not support cell arrays containing cell arrays or objects.
The funtion tries to redraw the last point selected via:
x0 = []; y0 = []; z0 = [];
inan = isnan([NaN; X; NaN])
if ~inan(end-1)
inan = find(inan);
nlastpoints = inan(end)-inan(end-1)-1
npoints = length(hpoints)
range = npoints-nlastpoints+1:npoints
hlastaxes = get(hpoints(range),'Parent');
assignin( 'base', 'hlastaxes', hlastaxes );
if iscell(hlastaxes), hlastaxes = cell2mat(hlastaxes); end
[loc,loc] = ismember(ha,hlastaxes);
if loc
x0 = get(hpoints(range(loc)),'XData');
y0 = get(hpoints(range(loc)),'YData');
z0 = get(hpoints(range(loc)),'ZData');
end
end
This worked fine in version 2014b, which would normally return a series of axes objects as numbers rather than a data array when using get( hpoints(range), 'Parent' ). Is there a simple fix to found out if the parent axes of that point is a member of the current axes?

Respuesta aceptada

Kelly Kearney
Kelly Kearney el 15 de Sept. de 2015
I've run into the same problem in many places with arrays of graphics handles... multidimensional arrays are perfectly fine, but functions like cell2mat, cellfun, and arrayfun don't allow arrays of handles as outputs. My solution is to use cat and reshape:
if iscell(hlastaxes)
hlastaxes = reshape(cat(1, hlastaxes{:}), size(hlastaxes));
end
You can skip the reshape part if your cell array is already a vector or if you don't care about preserving the shape:
hlastaxes = cat(1, hlastaxes{:});

Más respuestas (1)

Walter Roberson
Walter Roberson el 15 de Sept. de 2015
We need more information about the construction of hpoints.
As of R2014b, graphics objects are handles to objects, and certain operations that formerly worked to construct arrays that mixed graphics object double handles with other values in a cell array can now end up returning nested cell arrays instead. (I had it happen with one program; I have not hunted down the fix yet.)
To determine the axes that a point belongs to, use ancestor(ThePoint,'axes')

Categorías

Más información sobre Visual Exploration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by