Why is `struct('name', value)` different with dot notation?
1 回表示 (過去 30 日間)
古いコメントを表示
a = {{'abc'}};
S1 = struct('f', a};
S2.f = a;
I thought S1.f and S2.f have the same value. But it's not.
S1.f = {'abc'};
S2.f = {{'abc'}};
Why?
0 件のコメント
回答 (1 件)
Fangjun Jiang
2019 年 12 月 13 日
It is in the document. Check this example in the document. One creates a 1x2 struct array. The other creates a single struct.
>> s = struct('type',{'big','little'},'color','red')
s =
1×2 struct array with fields:
type
color
>> s = struct('type',{{'big','little'}},'color','red')
s =
struct with fields:
type: {'big' 'little'}
color: 'red'
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!