Merge structures with overlapping fieldname

Hello,
I'm trying to intelligently combine to data sets to create a new complete data set. The setup is as follows:
data.set1.ID = [457;568;422;8997;544;366];
data.set1.type = {'fish';'cat';'dog';'horse';'monkey';'yellow'};
data.set2.ID = [568;233;422;8997;366;78887;544;111];
data.set2.num = [68;55;44;22;89446;23447;5975;13544];
I would like the output to be a new structure with 3 fields, ID, type, and num that has been aligned by ID. If there isn't a num or type for a particular ID, it will just have a "NaN" placeholder.
I've tried finding and looping but it was slow and used up all of my RAM (my data set is large). It looks like there is a data type called a table in R2013b but I only have 2013a. I thought there had to be a better way. Thanks for any help you can provide!

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 15일

0 개 추천

d.ID=[data.set1.ID;data.set2.ID]
d.type=[data.set1.type;num2cell(repmat(nan,numel(data.set2.ID),1))]
d.num=[repmat(nan,numel(data.set1.ID),1);data.set2.num]
Sean de Wolski
Sean de Wolski 2014년 4월 15일

0 개 추천

You could do this in R2013a's Statistics Toolbox with the dataset class. If your organization is current on SMS, you can upgrade to the newest release.

카테고리

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

질문:

2014년 4월 15일

답변:

2014년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by