开发者

matlab - print subarray of two dimensional array

开发者 https://www.devze.com 2022-12-18 16:25 出处:网络
hi let\'s assume i have the following in matlab h = [0,0,0,1; 1,1,1,1];开发者_高级运维 now how can i print all the values of the first subarray, i.e. 0,0,0,1

hi let's assume i have the following in matlab

             h = [0,0,0,1;
                  1,1,1,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 !


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号