Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Variable syntax in Matlab

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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, if A is a 3-by-4 matrix, then size(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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading