Merge columns in two tables depending on column names

6 次查看(过去 30 天)
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 个)

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by