Indexing directly on a matrix literal

7 visualizaciones (últimos 30 días)
Bill Tubbs
Bill Tubbs el 3 de Feb. de 2020
Respondida: Divya Yerraguntla el 6 de Feb. de 2020
I'm assuming it's not possible in MATLAB to index directly on a matrix literal.
For example: Say I want to show the first 5 rows of all these vectors:
>> [t_sim, u_sim, y_sim, y_data](1:5,:)
[t_sim, u_sim, y_sim, y_data](1:5,:)
Error: Invalid expression. When calling a function or indexing a variable, use
parentheses. Otherwise, check for mismatched delimiters.
This works of course but requires an extra line and creating a variable:
>> temp = [t_sim, u_sim, y_sim, y_data];
>> temp(1:5,:)
ans =
0 -1.0000 0 0.3565
1.0000 1.0000 -0.9614 1.4867
2.0000 -1.0000 -0.6378 -1.5364
3.0000 1.0000 -1.2231 0.0902
4.0000 1.0000 -0.5430 -0.4092
>> clear temp
Presumably the MATLAB language is not parsed in a way that indexing is applied to "whatever comes before". Does that mean you can only index on a variable as above?
Can someone please confirm?

Respuestas (1)

Divya Yerraguntla
Divya Yerraguntla el 6 de Feb. de 2020

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by