Merge structures with overlapping fieldname
3 views (last 30 days)
Show older comments
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!
0 Comments
Answers (2)
Azzi Abdelmalek
on 15 Apr 2014
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]
0 Comments
Sean de Wolski
on 15 Apr 2014
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.
0 Comments
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!