Effacer les filtres
Effacer les filtres

Merge table with different rows

84 vues (au cours des 30 derniers jours)
Shelender Kumar
Shelender Kumar le 2 Nov 2018
Commenté : Star Strider le 9 Fév 2022
I have two files with different rows but with the same number of columns and I want to combine it together but I am getting an error * All tables in the bracketed expression must have the same number of rows. *
file1 = readtable('306K-268K.csv'); file2 = readtable('266K-228K.csv'); Com = [file1 file2];
Thanks a lot for the help

Réponse acceptée

Star Strider
Star Strider le 2 Nov 2018
You probably want the outerjoin (link) function:
Com = outerjoin(file1,file2);
See if that does what you want.
  4 commentaires
MattyK
MattyK le 9 Fév 2022
Thanks very much for this solution, have always wanted it. It works perfectly
Star Strider
Star Strider le 9 Fév 2022
@MattyK My pleasure!

Connectez-vous pour commenter.

Plus de réponses (4)

madhan ravi
madhan ravi le 2 Nov 2018
Modifié(e) : madhan ravi le 17 Nov 2018
You can't merge table with different number of size dimensions , use structure instead
  8 commentaires
Shelender Kumar
Shelender Kumar le 18 Nov 2018
Thanks a lot
madhan ravi
madhan ravi le 18 Nov 2018
Glad to help :)

Connectez-vous pour commenter.


Stéphane Rainville
Stéphane Rainville le 16 Nov 2018
You're missing a semi-colon to invoke vertical concatenation ('vertcat') rather than default horizontal concatenation ('horzcat').
For instance, two tables with different number of rows (but same number of columns), this does NOT work:
myBigTable = [myTable1 myTable2];
But this does:
myBigTable = [myTable1; myTable2];
I was facing a similar problem when storing tables of different lengths in a cell array.
myTables{1} = myTable1;
myTables{2} = myTable2;
and using
bigTable = [myTables{:}]
did not work because unwrapping and concatenating cell contents invoked horizontal concatenation. You can't just stick a semi-colon in there, so I had to explicitly invoke vertical concatenation like this:
bigTable = vertcat(myTables{:});
  2 commentaires
Shelender Kumar
Shelender Kumar le 17 Nov 2018
Modifié(e) : Shelender Kumar le 17 Nov 2018
Thanks for the help
but I want to place my file1 and file2 side by side. That means it should give me the data like horizcat
Stéphane Rainville
Stéphane Rainville le 17 Nov 2018
Ah I see. Then yeah, tables of different length would be a problem.

Connectez-vous pour commenter.


the cyclist
the cyclist le 2 Nov 2018
I'm guessing you need the join command.
  1 commentaire
Shelender Kumar
Shelender Kumar le 2 Nov 2018
I have some NAN values in my column so I am getting this error The key variables for A and B cannot contain any missing values.

Connectez-vous pour commenter.


Peter Perkins
Peter Perkins le 6 Nov 2018
"Merge" is kind of vague. It may be that you just need to add a semicolon to vertically concatenate:
Com = [file1; file2]
  3 commentaires
HabenG
HabenG le 3 Nov 2021
Modifié(e) : HabenG le 3 Nov 2021
Have you figured out the issues?? seems like there is no way to simply combine columns of different size matrrix, table, array etc...i feel like there should be a simple fuction for this
Peter Perkins
Peter Perkins le 8 Nov 2021
The current way to do this is to create the same number of rows in the smaller matrix/table/whatever. That's already been shown in an earlier reply.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by