Codeman
Codeman

Reputation: 12375

What is the MATLAB meaning of foo(x,y:z)

This is the sample code:

TorqueCurve = [0 400 800 1200 1600 2000 2400];
TorqueCurve(1,2:6);

I don't currently have a copy of MATLAB, so I can't test this myself, but I would like to know:

Am I correct in my assumption that the first declaration creates a single dimensioned variable with the contents 0, 400, 800, etc.?

What exactly, in prose (English), is the meaning of the second line? What is it accessing, and how?

Thanks in advance!

Upvotes: 0

Views: 3433

Answers (1)

Jonas
Jonas

Reputation: 74940

The first line declares an array of size 1-by-7 containing 0, 400, etc.

The second line extracts, from row 1, columns 2 through 6, and is equivalent to writing TorqueCurve(1,[2 3 4 5 6]).

The result, which you'll see printed to the command window if you evaluate that line without semicolon at the end, is 400 800 etc., since Matlab indexing is 1-based.

Upvotes: 3

Related Questions