hi.how to convert cell array to table?. i tried using cell2table() but it shows an error 'invalid function for the type cell'
2 views (last 30 days)
Show older comments
alankrita asthana
on 13 Dec 2017
Commented: Kimberly Andersen
on 28 Sep 2020
if true
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height =[71;69;64;67;64];
Age=cellstr(num2str(Age));
Height=cellstr(num2str(Height));
T = [{'','age','height'};[LastName,Age,Height]];
t=cell2table(T)
end
0 Comments
Accepted Answer
Jan
on 13 Dec 2017
Edited: Jan
on 13 Dec 2017
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49]; % No need to convert this to strings
Height = [71;69;64;67;64];
C = cat(1, LastName.', num2cell(Age.'), num2cell(Height.'));
T = cell2table(C, 'VariableNames', {'name', 'age', 'height'})
According to https://www.mathworks.com/help/matlab/ref/cell2table.html this should work. If you get a message like "invalid function for the type cell" (by the way: please post a copy of the complete message), you might work with a Matlab version older than R2013b, which did not have the table objects. Otherwise please look in your documentation about a working example:
doc cell2table
Try to run the examples. What do you observe? What is the difference to your code?
3 Comments
Jan
on 13 Dec 2017
Sorry, R2013a did not have the cell2table command. table objects have been introduced in R2013b. I do not know, which "ExportToPPTX" function you mean, but I do not assume, that it requires modern table objects.
If you mean https://www.mathworks.com/matlabcentral/fileexchange/40277-exporttopptx, why do you think that you need a table object at all? The documentation contains an example, where a table is created directly from a cell array, see example.
Kimberly Andersen
on 28 Sep 2020
C comes out as a 3x5 cell array and needs to be a 5x3 array to form the table T
More Answers (0)
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!