cell2class

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.4, Creation date: 2018-12-30, Last change: 2025-09-14

converts a cell list of elements of the same class into an array of this class

Description

In more and more cases, the get command of matlab returns cell lists of specific classes, but the methods of those classes are unable to process cell lists. Therefor this function converts a cell list into an array of the class type

See Also: , arrayof , class2cell , array2cell

Example Illustration

 missing image of cell2class(cells)

Syntax

x=cell2class(cells)

Input Parameter

cells: cell list of any class type

Output Parameter

x: resulting array of the class type

Examples


SGfigure; CPLplotasPS(CPLsample(14)); h=findobj(gca,'type','polygon')
a=get(h,'Shape'), x=cell2class(a)
cla; plot(x); shg




Copyright 2018-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

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.

Input Parameters

Output Results

Algorithm Steps

  1. Determine the size of the input cell list cells using the size function and store it in n.
  2. Initialize the output array 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.
  3. Iterate over each element in the cell list using a for loop. The loop runs from 1 to the total number of elements in x, as determined by numel(x).
  4. Within the loop, assign each element from cells to the corresponding position in x. This effectively converts the cell list into an array of the same class type.

Example Usage

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.

Algorithm explaination created using ChatGPT on 2025-08-19 00:37. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21