hi.how to convert cell array to table?. i tried using cell2table() but it shows an error 'invalid function for the type cell'

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Jan
Jan el 13 de Dic. de 2017
Editada: Jan el 13 de Dic. de 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 comentarios
Jan
Jan el 13 de Dic. de 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
Kimberly Andersen el 28 de Sept. de 2020
C comes out as a 3x5 cell array and needs to be a 5x3 array to form the table T

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by