display content of column of array in matlab

Assuming you have an array A in MATLAB, and you want to display a specific column of that array, you can use the following syntax:

main.m
A(:, col)
10 chars
2 lines

Here col is the index of the column you want to display. The : before col indicates that we want to select all rows in that column.

For example, if A is a 2D array with 5 rows and 3 columns, and you want to display the second column:

main.m
A = [1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15];
col = 2;
A(:, col)
66 chars
4 lines

This will output:

main.m
ans =
     2
     5
     8
    11
    14
41 chars
7 lines

Alternatively, you can also use the disp function to display the column, like this:

main.m
disp(A(:, col))
16 chars
2 lines

This will give you the same result.

related categories

gistlibby LogSnag