cell2table only using first cell array row
4 views (last 30 days)
Show older comments
I have a cell array as such:
E =
4x1 cell array
{1x4 cell}
{1x4 cell}
{1x4 cell}
{1x4 cell}
Where each 1x4 cell array consists of a char array.
E{1} =
{'Input'} {'azimuth_1p'} {'real'} {'-inf to inf'}
However the following code
T = cell2table(E{1,:},'VariableNames',{'IO_Type', 'Name', 'Type', 'Range'});
Only gives me the following table:
IO_Type Name Type Range
_______ ______________ ______ _____________
'Input' 'azimuth_1p' 'real' '-inf to inf'
Why aren't I getting all 4 rows in my table?
0 Comments
Answers (1)
Guillaume
on 30 Jul 2018
Why aren't I getting all 4 rows in my table?
Matlab does exactly what you asked. As you've shown E is a 4 (rows) x 1 (column) cell array. E{1, :} is the content of the 1st row and all the columns. There's only one column, so E{1, :} is the same as E{1, 1} or E{1}. The content of E{1} is a 1 (row) x 4 (column) cell array, hence you only get one row out of cell2table.
Note that if E had more than one column, then cell2table(E{1, :}, ...)| would have been equivalent to:
cell2table(E{1, 1}, E{1, 2}, E{1, 3}, ... )
which would have most likely errored unless E{1, 2}, etc. contained valid options for cell2table.
To convert your cell array of cell arrays to a table. First concatenate all the rows so you have a 4x4 cell array, then call cell2table:
T = cell2table(vertcat(E{:}), 'VariableNames',{'IO_Type', 'Name', 'Type', 'Range'});
You may want to review how you construct E so it is a 4x4 cell array (of char arrays) instead of a 4x1 cell array of 1x4 cell arrays (of char arrays)
0 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!