get rows of array in matlab

In MATLAB, you can get rows of an array by using the colon operator to specify the range of rows you want to extract. Here is an example:

main.m
% Create a 3-by-4 array
A = [1 2 3 4; 5 6 7 8; 9 10 11 12];

% Extract the second row
row2 = A(2,:);
disp(row2);
% Output: [5 6 7 8]

% Extract the first and third rows
rows1and3 = A([1 3],:);
disp(rows1and3);
% Output: 
%      1     2     3     4
%      9    10    11    12
275 chars
15 lines

In both cases, we used the colon operator to specify all columns of the desired rows. The resulting variable is a row vector containing the values of the specified rows.

gistlibby LogSnag