Syntax
A=cell2array(C)
Input Parameter
C : | | cell array of number rows of different length |
Output Parameter
A : | | Array with constant number of columns, NaN |
Copyright 2014-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, 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
.
Input Parameters
- C: A cell array where each cell contains a row of numbers. The rows can have different lengths.
Output Results
- A: A 2D array where each row corresponds to a cell in
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
.
Algorithm Steps
- Determine the number of rows,
n
, in the cell array C
using size(C,1)
.
- Initialize a variable
m
to zero. This will store the maximum row length found in C
.
- Iterate over each row
i
in C
to find the maximum row length:
- For each row
C{i}
, determine its length k
using size(C{i},1)
.
- Update
m
to be the maximum of its current value and k
.
- Create an
n
by m
array A
filled with NaN
using nan(n,m)
.
- Iterate over each row
i
in C
again to populate A
:
- Determine the length
k
of the current row C{i}
.
- If
k
is greater than zero, copy the elements of C{i}
into the first k
columns of the i
-th row of A
.
Algorithm explaination created using ChatGPT on 2025-08-18 22:51. (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