by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 2.1, Creation date: 2014-12-30, Last change: 2025-09-14
A=cell2array(C)
C: | cell array of number rows of different length |
A: | Array with constant number of columns, NaN |
This function, cell2array, is designed to convert a cell array with rows of varying lengths into a 2D array with a consistent number of columns. The function is part of the SolidGeometry library and was introduced in version 2.1. It may be considered obsolete due to the existence of cell2mat.
C. The number of columns is equal to the length of the longest row in C. If a row in C is shorter than the longest row, the remaining elements in that row of A are filled with NaN.n, in the cell array C using size(C,1).m to zero. This will store the maximum row length found in C.i in C to find the maximum row length:
C{i}, determine its length k using size(C{i},1).m to be the maximum of its current value and k.n by m array A filled with NaN using nan(n,m).i in C again to populate A:
k of the current row C{i}.k is greater than zero, copy the elements of C{i} into the first k columns of the i-th row of A.