Here is an example matrix A
of Dimensions 6x3x8x5
Now if i use size(A)
, i get all the dimensions as a row vector
ans = [6 3 8 5]
If i want to get specific dimension(singular), i could use something like size(A,1)
or size(A,3)
etc..
What if i want specified set of dimensions for eg, size of 3rd and 4th dimensions or 2nd to nth dimension
What i want to do is something like size(A,3:4)
or size(A,2:n)
or size(A,[1 3 4])
But from the Doc, it appears that, input dimensions for size could only be a scalar. When i try to do this, i get this error:
>> size(A,[2 3])
Error using size
Dimension argument must be a positive integer scalar within indexing range.
I'm expecting the output to be
ans = [3 8]
FYI:
I'm trying to pass this as an input argument into another function like this:
out = someFunction(arg1,arg2,size(A,[2 3]))
What i'm currently doing is
[~,size2,size3,~] = size(A)
out = someFunction(arg1,arg2,[size2, size3])
I just wanted to use it directly without the first line. Obviously when we have only two dimensions, we use it directly just by doing size(A)
. why not in this case? Any alternative to make this a one-liner?
size
function that has the features you describe. – horchlersize
is a function which returns an array, and you want to index it, without first assigning it to a local variable. You just gave a name to the "function" - the rest is equal :) – Robert Seifertsize
, which brings the duplicate question to the only possible solution. Just let the community decide, if it's duplicate or not :) You don't need to accept the duplicate suggestion – Robert Seifertsize
function in any future release, these 2 questions will be completely different. Just saying ;) – Santhan Salai