convert a table into a cell array in matlab

To convert a table into a cell array, you can use the table2cell function in MATLAB as follows:

% create a table
T = table([1;2;3], {'A';'B';'C'}, [true;false;true], 'VariableNames',{'Var1' 'Var2' 'Var3'});

% convert table to cell array
C = table2cell(T);
161 chars
6 lines

This will convert the table T to a cell array C, where each row of the cell array corresponds to a row of the table and each column of the cell array corresponds to a variable in the table.

Note that if your table has row names (specified using the RowNames parameter), the table2cell function will include them as the first column of the cell array. If you want to exclude the row names, you can use the removevars function to remove them before calling table2cell. For example:

% create a table with row names
T = table([1;2;3], {'A';'B';'C'}, [true;false;true], 'VariableNames',{'Var1' 'Var2' 'Var3'}, 'RowNames',{'Row1' 'Row2' 'Row3'});

% remove row names from the table
T_noRowNames = removevars(T, 'RowNames');

% convert table to cell array
C = table2cell(T_noRowNames);
299 chars
9 lines

This will create a cell array C without the row names.

related categories

gistlibby LogSnag