Indexing directly on a matrix literal

6 vues (au cours des 30 derniers jours)
Bill Tubbs
Bill Tubbs le 3 Fév 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?

Réponses (1)

Divya Yerraguntla
Divya Yerraguntla le 6 Fév 2020

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by