Take the 2-minute tour ×

hi let's assume i have the following in matlab

             h = [0,0,0,1;

now how can i print all the values of the first subarray, i.e. 0,0,0,1

or for example the second subarray 1,1,1,1. thanks !

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can access just the first row of your matrix by doing

   firstRow = h(1,:)

Similarly, you could access just the third column by

   thirdColumn = h(:,3)

I suggest you look into the MATLAB help under "Matrix Indexing" as this is really basic stuff (and there's a lot of other nifty things you can do to access a subset of a matrix)

For printing, you can omit the final ;, or look into functions display and fprintf.

share|improve this answer

Your Answer


