Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: How to generate 0x0 struct array?

I got an .mat file with a variable X:

>> open('3rdPartyInputfile.mat')
>> X

X = 

0x0 struct array with fields:
    a
    b

I tried to create a similar variable like:

>> X1(1).a = [];
>> X1(1).b = [];
>> X1(1)=[]

X1 = 

1x0 struct array with fields:
    a
    b


>> X2(1).a = [];
>> X2(1).b = [];
>> X2(:,:)=[]

X2 = 

0x1 struct array with fields:
    a
    b

Which is close but not identical. The size here are 1x0 or 0x1, instead of the desired 0x0.

How to get it to 0x0?

like image 905
BerndGit Avatar asked Dec 14 '22 17:12

BerndGit


2 Answers

To get a 0x0 struct you can use

X = struct('a',{},'b',{})
like image 83
Nemesis Avatar answered Dec 17 '22 07:12

Nemesis


In case you have an existing struct x and want to scale it down to 0x0, you could do the following:

 y=repmat(x,0,0)
like image 38
Dennis Jaheruddin Avatar answered Dec 17 '22 07:12

Dennis Jaheruddin