convert cell array to table in matlab

To convert a cell array to a table in Matlab, you can use the cell2table function. This function takes a cell array as the input and returns a table object.

Here is an example code:

main.m
% create a cell array
cellArray = {
    'John', 25, 'M';
    'Jane', 30, 'F';
    'Bob', 45, 'M'
};

% convert cell array to table
tableObj = cell2table(cellArray, 'VariableNames', {'Name', 'Age', 'Gender'});

% display table
disp(tableObj);
242 chars
13 lines

In this example, we create a cell array with three columns, representing name, age, and gender. We then use the cell2table function to convert this cell array to a table object. We also specify the variable names for the table using the 'VariableNames' parameter. Finally, we display the resulting table using the disp function.

The output of the code above will be:

main.m
         Name         Age      Gender
    ___________    ___    ______

    'John'          25     'M'    
    'Jane'          30     'F'    
    'Bob'           45     'M'    
177 chars
7 lines

This shows that the cell array has been successfully converted to a table.

gistlibby LogSnag