Creating a table with every possible combination of rows from other tables
21 views (last 30 days)
Show older comments
Hello,
I currently have multiple tables with different sets of information in. I am wanting to create one large table that includes all the possible combinations of all of these sets of data in. For example, it would create a table by taking the first row of the first table and then iterating through all of the remaining tables until all possible combinations had been displayed in a table. Is there a way to do this?
Many thanks for your help,
Josh
2 Comments
the cyclist
on 20 Mar 2021
What you want to do is not clear to me. Showing a small example of the input and output would be very helpful in understanding what you mean.
Answers (1)
Gargi Patil
on 24 Mar 2021
If my understanding is right, you have multiple tables with each row corresponding to the various test scores for a student. The desired output should present an exhaustive combination such that each combination has all the tests listed and a particular student is chosen for each test.
A possible workaround to the problem could be to display the scores of the students in the output for each test instead of the student names. You can then map the scores to the corresponding students.
The above can be achieved by extracting the scores of all the students for a particular test as a vector. You can then run the following code:
%Let test1, test2, test3, test4 be vectors containing test scores
[W, X, Y, Z] = ndgrid( test1, test2, test3, test4);
out = [W(:), X(:), Y(:), Z(:)];
Each row of the output matrix ‘out’ will contain a possible combination with the score of the student displayed for the test. The combined score can be calculated summing across the values of the row.
You can refer to the further link for more information:
0 Comments
See Also
Categories
Find more on Outputs 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!