save a row from a table in a cell array in matlab

Suppose you have a table T. You can save a row from this table into a cell array C using the following code:

main.m
C = table2cell(T(1,:));
24 chars
2 lines

This will save the first row of table T into a cell array C. You can replace the 1 with any row number you want to save. Also, note that the table2cell function is used to convert the table row into a cell array.

If you want to save multiple rows from the table into a cell array, you can use a loop:

main.m
numRows = 5;
C = cell(numRows,1);
for i = 1:numRows
    C{i} = table2cell(T(i,:));
end
87 chars
6 lines

This will save the first 5 rows of table T into a cell array C, with each row being saved in a separate cell. Change the value of numRows to save any number of rows you want.

related categories

gistlibby LogSnag