Indexing directly on a matrix literal

6 views (last 30 days)
Bill Tubbs
Bill Tubbs on 3 Feb 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?

Answers (1)

Divya Yerraguntla
Divya Yerraguntla on 6 Feb 2020

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!