I have a piece of MATLAB code that I want to translate to python, here is the relevant part of code:
assuming x = [1,2,3,4,5]:
% The size of x
N=size(x);
N=N(2);
The issue is at the second line. I understand the index syntax if it was say x(2), but N(2) I don’t understand. I’ve tried looking at what this means in the documentation, but all I could find was for indexing lists.
Any help is appreciated, thanks.
>Solution :
As explained in official documentation of size(),
sz = size(A)returns a row vector whose elements are the lengths of the corresponding dimensions of A. For example, ifAis a 3-by-4 matrix, thensize(A)returns the vector[3 4].
In Matlab, the first dimension is row. Second is column. Since N is a row vector. N(2) returns the 2nd element of this vector. As explained in the documentation, that is the length of the 2nd dimension, ie. the column index.
It is equivalent as getting the second output parameter sz2 as follows.
[sz1,...,szN] = size(___)returns the lengths of the queried dimensions of A separately.