Info

This question is closed. Reopen it to edit or answer.

Very basic: Could someone please explain what the 2 stands for in "size(v,2)" ?

1 view (last 30 days)
V=[5 6 7 8]
size(v,2)
Could someone please explain what the 2 stands for in "size(v,2)" ?

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 28 Apr 2020
You'll need to learn to read the help and doc for matlab-functions and commands. Also: welcome to matlab.
For this time only: size(v,2) will give you the size of v in the second dimension.
HTH
  3 Comments
Steven Lord
Steven Lord on 28 Apr 2020
When you call size with one input argument and one output argument (which you are when you use it as the input to another function or operator), the output argument is a vector whose element k is the size of that input in dimension k.
matrix3x4x5 = rand(3, 4, 5);
size(matrix3x4x5) % [3 4 5]
When you call the colon operator : with a vector for one of the endpoints (or the increment) MATLAB ignores all elements other than the first.
aVector = [4 6 9 22 Inf];
anotherVector = 1:aVector % equivalent to 1:aVector(1) or 1:4
When you call size with two input arguments, the output is the size of the first input in the dimension specified by the second input. If that second input is 1, the output is the number of rows in the first input (basically how many rows get "collapsed" into one in the picture in the description of the dim input argument on this documentation page.) A second input of 2 gives the number of columns in the first input.
size(matrix3x4x5, 2) % 4 since size(matrix3x4x5) returns [3 4 5]

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!