Indexing directly on a matrix literal

4 ビュー (過去 30 日間)
Bill Tubbs
Bill Tubbs 2020 年 2 月 3 日
回答済み: Divya Yerraguntla 2020 年 2 月 6 日
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?

回答 (1 件)

Divya Yerraguntla
Divya Yerraguntla 2020 年 2 月 6 日

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by