how to put rows of a cell matrix into a cell array in matlab

To put rows of a matrix into a cell array in Matlab, you can use a loop to iterate through the rows and use indexing to extract each row and store it in the cell array. Here's an example code:

main.m
% Create a matrix
matrix = [1 2 3; 4 5 6; 7 8 9];

% Get number of rows and columns of the matrix
num_rows = size(matrix, 1);
num_cols = size(matrix, 2);

% Create a cell array
cell_array = cell(num_rows, 1);

% Iterate through rows of the matrix and store them in the cell array
for i = 1:num_rows
    cell_array{i} = matrix(i,:);
end
336 chars
15 lines

This code creates a matrix and a cell array of the same number of rows. It then iterates through each row of the matrix, extracts the row using indexing, and saves it in the corresponding element of the cell array.

gistlibby LogSnag