フィルターのクリア

How to index the value returned by a Map

24 ビュー (過去 30 日間)
Bill Tubbs
Bill Tubbs 2020 年 2 月 4 日
コメント済み: Bill Tubbs 2020 年 3 月 19 日
I'm new to MATLAB so please help me out here.
I have a containers.Map that contains cell arrays. I want to get one of the cell arrays and immediately index an item from it.
I tried simply putting the curly braces after the Map's key index and got this error message:
>> stats('u_est')
ans =
1×5 cell array
{[525]} {[0.9834]} {[-0.0261]} {[-1.0166]} {[1.0009]}
>> stats('u_est'){2}
Error: Indexing with parentheses '()' must appear as the last operation of a valid indexing expression.
Obviously I can do it by assigning a new variable but I think there must be a way to do it directly:
>> values = stats('u_est');
>> values{2}
ans =
0.9834
Also, what does it mean by "Indexing with parentheses '()' must appear as the last operation of a valid indexing expression"?
thanks
  2 件のコメント
Tobias Ohrmann
Tobias Ohrmann 2020 年 3 月 19 日
@Bill Tubbs I have exactly the same problem, did you manage to solve it? Defining a new variable seems very laborious here..
Bill Tubbs
Bill Tubbs 2020 年 3 月 19 日
No. As far as I know, this kind of 'chained expression evaluation' is an inherent non-feature of MATLAB. The only solution I know is to switch to another language such as Python that parses all the sub-components of an expression with a consistent set of rules and can thus handle compound operations on any objects of valid type.

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

回答 (1 件)

KSSV
KSSV 2020 年 2 月 4 日
YOu have to use
u_est = values{2} ;
For arrays the indexing is done using (), for cells indexing is done using {}.
  4 件のコメント
Bill Tubbs
Bill Tubbs 2020 年 2 月 4 日
Thanks but I am asking if it is possible to get a cell array from a Map and immediately index an item from it. Or is this impossible to do in one statement? If you look at the second code segment it shows that I know how to do it in two steps. The question is can I do it in one? Like this:
stats('u_est'){2}
Bill Tubbs
Bill Tubbs 2020 年 2 月 4 日
編集済み: Bill Tubbs 2020 年 2 月 4 日
Basically I'm trying to do this in MATLAB:
>>> stats = {'u_est': [525, 0.9834, -0.010]}
>>> stats['u_est'][1]
0.9834

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

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by