Merge table with different rows
54 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
その他の回答 (4 件)
madhan ravi
2018 年 11 月 2 日
編集済み: madhan ravi
2018 年 11 月 17 日
You can't merge table with different number of size dimensions , use structure instead
8 件のコメント
Stéphane Rainville
2018 年 11 月 16 日
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 件のコメント
Stéphane Rainville
2018 年 11 月 17 日
Ah I see. Then yeah, tables of different length would be a problem.
Peter Perkins
2018 年 11 月 6 日
"Merge" is kind of vague. It may be that you just need to add a semicolon to vertically concatenate:
Com = [file1; file2]
3 件のコメント
Peter Perkins
2021 年 11 月 8 日
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.
参考
カテゴリ
Help Center および File Exchange で Other Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!