square brackets indexing of vectors

8 views (last 30 days)
c c
c c on 13 Oct 2011
Edited: John D'Errico on 15 Nov 2020
This is for next releases: why matlab doesn't allow also square brackets indexing of vectors ? the meaning should be
vec[k] == vec(1+k) with k ranging from 0 to length( vec ) - 1
Reasons: Digital logic indexing naturally starts from zero. Also, porting from/to C should be easier.
  1 Comment
Walter Roberson
Walter Roberson on 13 Oct 2011
I suggest you add this to the existing indexing suggestions in
http://www.mathworks.com/matlabcentral/answers/1325-what-is-missing-from-matlab

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 15 Nov 2020
Edited: John D'Errico on 15 Nov 2020
This has never existed as an option, and I doubt it ever will. That is, there is no need for [] bracket indexing to exist, since () are fully capable of doing what you want. It would be foolish to make the language more complex to perform the same operations multiple ways, with no gain from the additional complexity. See that this would make the existing parsing code considerably more complicated. The net result would be people would need to be hired to write the code, to maintain it, to debug it.
While nothing stops you from requesting this as a feature, you would want to show why and how anyone would gain from the additional complexity.

Products

Community Treasure Hunt

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

Start Hunting!