Indexing result of strsplit('My string', ' ')

Why doesn't something like
strsplit('My string', ' ')(1)
work?
Is there a more elegant way than
x = strsplit('My string', ' ')
x(1)

 採用された回答

Guillaume
Guillaume 2018 年 6 月 20 日

2 投票

No matlab does not allow indexing directly into the return value of a function (or any other temporary variable). There is not workaround other than assigning the temporary to a variable, as you have done.
Note that if you want the content of the first element of the cell array {} would be more appropriate
x = strsplit('My string', ' ')
x{1}

1 件のコメント

Nicolas Bourbaki
Nicolas Bourbaki 2018 年 7 月 24 日
Thanks a lot for your answer. It helps me a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

製品

リリース

R2018a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by