Why is `struct('name', value)` different with dot notation?

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?

답변 (1개)

Fangjun Jiang
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'

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2019년 12월 13일

답변:

2019년 12월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by