MATLAB error with indexing

What does this code : Y = eye(10)(y,:); do? Assume that y is an 5000 x 1 vector,when I try to execute that line of code it yields an error :
()-indexing must appear last in an index expression.
I need a bit help.

Respuestas (1)

Adam
Adam el 11 de Dic. de 2014
Editada: Adam el 11 de Dic. de 2014

0 votos

Well, that is exactly what it does - it yields an error!
Unlike C++ or Java or other languages you cannot chain together (or whatever the official software engineering terminology is!) parenthesis like that.
You have to do:
Y = eye(10);
Y = Y(y,:);
in two lines to achieve that. Although with the example you give that would also potentially yield an error because eye(10) is a 10*10, 100 element matrix so unless your 5000-element matrix, y, contains only values < 100 you will still get an index exceeds dimensions error.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 11 de Dic. de 2014

Editada:

el 11 de Dic. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by