size function
https://www.gnu.org/software/octave/doc/v4.0.1/Object-Sizes.html#XREFsize
Built-in Function: size (a)
Built-in Function: size (a, dim)
Return the number of rows and columns of a.
With one input argument and one output argument, the result is returned in a row vector. If there are multiple output arguments, the number of rows is assigned to the first, and the number of columns to the second, etc. For example:
size ([1, 2; 3, 4; 5, 6])
⇒ [ 3, 2 ]
[nr, nc] = size ([1, 2; 3, 4; 5, 6])
⇒ nr = 3
⇒ nc = 2
If given a second argument, size will return the size of the corresponding dimension. For example,
size ([1, 2; 3, 4; 5, 6], 2)
⇒ 2
returns the number of columns in the given matrix.
Testing:
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66;55 ,476, 22]
a =
1 2 33
4 5 6
7 8 66
55 476 22
[rows columns]=size(a);
rows = 4
columns = 3
size(a,1) # 1 means get rows ; 2 means get columns
ans = 4
size(a,2)
ans = 3
-------------------------------------------------------------------------------
沒有留言:
張貼留言