disp() specific column of array in matlab

To display a specific column of an array in MATLAB, you can use indexing. Here is an example:

main.m
% create a 3x3 array
A = [1 2 3; 4 5 6; 7 8 9];

% display the second column
disp(A(:,2));
91 chars
6 lines

The : operator is used to indicate that we want to select all rows of the array, and 2 indicates that we want to select the second column.

If you want to select multiple columns, you can use a vector of column indices:

main.m
% select the first and third columns
disp(A(:,[1 3]));
55 chars
3 lines

This will display the first and third columns of A.

Note that disp prints the column vector vertically. If you want to display it horizontally, you can use the fprintf function:

main.m
% display the second column horizontally
fprintf('%d ', A(:,2));
fprintf('\n');
80 chars
4 lines

related categories

gistlibby LogSnag