Merge columns in two tables depending on column names

조회 수: 8 (최근 30일)
Vlatko Milic
Vlatko Milic 2021년 12월 8일
댓글: Vlatko Milic 2022년 1월 11일
Hi,
I have two tables consisting of six and 21 columns. I want to create three new tables based on the column names in the aforementioned tables. This I want to perform depending on the 10th and 12th position in the first table with six columns (see Mat_question-file). The 10th and 12th position contains values of 1/2, 3/4 or 5/6. These values (i.e. 1/2, 3/4 or 5/6) in the first table, I want to merge with the columns in table no.2 based on position 7. Position 7 in the second table (21 columns) contains the values of 2,3 or 6 ( see Mat_question2-file). I want to merge all the columns in the second table with the same value, i.e. 2,3 and 6, on the 7th position. Thereafter, I want to to merge the already merged columns from the second table with the first table based on if the 10th or 12th value in each column (table 1) contains a 1 or 2, a 3 or 4, or a 5 or 6. Hence, as an example, the columns in table 2 that contain a 3 on the 7th position should be connected with the columns in table 1 that contain a 3 on the 10th or 12th position. Based on this I should get three new tables with the conditions described above.
Quite a messy problem. Happy to elaborate.
The files are attached in the question.
Thanks in advance MatLab-friends
  댓글 수: 1
Alex Normanie
Alex Normanie 2022년 1월 6일
Following - I need to learn how to use conditions for some merging operations too! thanks for posting

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

채택된 답변

Jon
Jon 2021년 12월 8일
I think you can probably accomplish what you want using one or more of MATLAB's join, innerjoin, and outerjoin commands.
Please look at the documentation for those, try to code up as far as you can get and if you are still stuck post for more help.
  댓글 수: 31
Stephen23
Stephen23 2022년 1월 11일
"However, the code cannot recognize my created columns when I do like this. I get the error ..."
Because your code design is liable to bugs and makes debugging much harder.
You are going to spend a lot of time fighting the otherwise trivial task of just trying to access your data.
Perhaps it is slowly time to learn the EVAL-sized lesson here: read the links we gave you and understand some of the reasons why the makers of MATLAB and all experienced MATLAB users advise against your approach to writing code.
Vlatko Milic
Vlatko Milic 2022년 1월 11일
I will do so Stephen, Jon appended some links before also. Thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by