x=cell2class(cells)
cells : | cell list of any class type |
x : | resulting array of the class type |
SGfigure; CPLplotasPS(CPLsample(14)); h=findobj(gca,'type','polygon')
a=get(h,'Shape'), x=cell2class(a)
cla; plot(x); shg
This function, cell2class
, is designed to convert a cell list of elements of the same class into an array of that class. It is particularly useful when dealing with MATLAB's get
command, which often returns cell lists that cannot be directly processed by class methods.
cells
using the size
function and store it in n
.x
using repmat
to replicate the first element of cells
across the dimensions specified by n
. This ensures that x
is of the same class type as the elements in cells
.for
loop. The loop runs from 1 to the total number of elements in x
, as determined by numel(x)
.cells
to the corresponding position in x
. This effectively converts the cell list into an array of the same class type.The function can be used in a scenario where graphical objects are manipulated:
SGfigure; CPLplotasPS(CPLsample(14)); h=findobj(gca,'type','polygon'); a=get(h,'Shape'); x=cell2class(a); cla; plot(x); shg;
In this example, graphical objects of type 'polygon' are found and their shapes are retrieved as a cell list. The cell2class
function then converts this list into an array, which can be plotted directly.