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)
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

Accepted Answer

Jan
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
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.

Sign in to comment.

More Answers (0)

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!