Matlab Bug? cell array of containers.Map

I have two expressions. In my opinion, both are equal. But one works, the other causes a matlab error.
for your info: obj.TabData is a 2×1 cell array [103×1 containers.Map] [163×1 containers.Map]
expression 1)
mapObj = obj.TabData{1}
causes "Expected one output from a curly brace or dot indexing expression, but there were 3 results."
expression 2)
temp = obj.TabData;
mapObj = temp{1};
works. mapObj is Map with properties: Count: 103 KeyType: char ValueType: any afterwards.
Is this a Matlab Bug? Or can anyone explain this behavior, please?

 採用された回答

Stephen23
Stephen23 2018 年 8 月 1 日
編集済み: Stephen23 2018 年 8 月 1 日

0 投票

"In my opinion, both are equal"
They aren't.
"Is this a Matlab Bug?"
No.
"Or can anyone explain this behavior, please?"
Your code does what I would expect if obj was not scalar. Basically you are doing this:
>> obj = struct('blah',{{1,1},{2,2},{3,3}})
obj =
1x3 struct array with fields:
blah
>> x = obj.blah{1} % cell indexing into comma-separated list -> error
Field reference for multiple structure elements that is followed by more reference blocks is an error.
>> x = obj.blah % take first output of comma-separated list -> no error
x =
[1] [1]
>> x{1}
ans =
1
Read this to know why the second example works:

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by