How do I merge two data sets into one table when they don't match in the number of their rows.

2 views (last 30 days)
I have two data sets that I'm trying to merge together. The first data set contains a quantity column. (ex. quantity of units = 3) and the second data set contains a row for each individual unit. Put simply, the second data set has much more rows than the first data set. What program can I write to extract all the rows from these data sets, and put them into a table (preferably in excel) so I can merge them together. Thanks so much for your input. Matlab is so great because of its incredible community.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jun 2011
Do you mean dataset as in a data type (such as from the statistics toolbox), or do you mean dataset as in simply an array of values?
Is there some kind of unit key shared between the two?
SecondSet(:,end+1) = 0; %create a new quantity column
[tf, idx] = ismember(FirstSet(:,IDColumn1),SecondSet(:,IDColumn2));
SecondSet(idx(tf),end) = FirstSet(tf,QuantityColumn);

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!