Merge columns in two tables depending on column names

6 visualizzazioni (ultimi 30 giorni)
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 Commento
Alex Normanie
Alex Normanie il 6 Gen 2022
Following - I need to learn how to use conditions for some merging operations too! thanks for posting

Accedi per commentare.

Risposta accettata

Jon
Jon il 8 Dic 2021
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 Commenti
Stephen23
Stephen23 il 11 Gen 2022
"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 il 11 Gen 2022
I will do so Stephen, Jon appended some links before also. Thanks

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by