Creating a table with every possible combination of rows from other tables

조회 수: 34 (최근 30일)
Josh Beaumont
Josh Beaumont 2021년 3월 20일
답변: Gargi Patil 2021년 3월 24일
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
the cyclist
the cyclist 2021년 3월 20일
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.
Josh Beaumont
Josh Beaumont 2021년 3월 23일
Sorry, I haven't explained it very well.
For example, if there were multiple tables with different students names (A,B,C,...) and the scores they got in different tests (1,2,3,...) would be the input. The desired output would be a table showing all of the possible combinations of students and the test they take and the addition of all of their scores to see which combination of students/tests would give the highest/lowest score . For example, one row would display which student was selected for each test and the combined score. The next row would then display the next possible combination.
I hope that this is a bit clearer than my original question.
Thanks for your help,
Josh

댓글을 달려면 로그인하십시오.

답변 (1개)

Gargi Patil
Gargi Patil 2021년 3월 24일
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:

카테고리

Help CenterFile Exchange에서 Testing Frameworks에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by