How to index the value returned by a Map
22 次查看(过去 30 天)
显示 更早的评论
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
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..
回答(1 个)
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!