convert cell array to normal cell in matlab

You can use the cell2mat function to convert a cell array to a normal array. Here's the syntax:

main.m
new_cell = cell(1,3); % create a cell array
new_cell{1} = 'apple'; % add some data to the cell array
new_cell{2} = 'banana';
new_cell{3} = 'orange';

normal_cell = cell2mat(new_cell); % convert the cell array to a normal cell
disp(normal_cell); % display the normal cell
271 chars
8 lines

Note that cell2mat only works if all the cells in the array are the same size (i.e., contain the same number of elements). If your cells are not the same size, you can use nested for loop to copy the elements of cell array to a normal cell.

main.m
new_cell = cell(2,2); % create a cell array
new_cell{1} = [1 2 3];
new_cell{2} = [4 5];

normal_cell = {};

for i=1:size(new_cell, 1)
    for j=1:size(new_cell, 2)
        normal_cell{i,j} = new_cell{i,j};
    end
end

disp(normal_cell);
238 chars
14 lines

related categories

gistlibby LogSnag