Merge tables with different dimensions?
Ältere Kommentare anzeigen
Hi,
I'm trying to use vertcat to add together a sequence of tables. The problem is, some are 24x22, some are 24x19, etc.
Matlab returns the error
Error using table/vertcat (line 56)
All tables in the bracketed expression must have the same number
of variables.
Is there a way to work around this? Like, adding empty columns?
Thanks so much.
Akzeptierte Antwort
Weitere Antworten (2)
Sterling Baird
am 5 Sep. 2020
Bearbeitet: Sterling Baird
am 5 Sep. 2020
1 Stimme
I built on Guillaume's answer a while back, and recently ended up making and submitting a FEX function (tblvertcat) that supports cells in addition to other types which are supported by "missing" (double, char, etc.).
EDIT: I revamped the code to use outerjoin()
1 Kommentar
Utsav Dave
am 19 Okt. 2023
Awesome! Saved me so much time, thanks Sterling!
Does this example do what you need?
A = randi(9,4,3)
B = randi(9,4,5)
C = randi(9,4,2)
D(1:4,1:size(A,2)) = A;
D(5:8,1:size(B,2)) = B;
D(9:12,1:size(C,2)) = C
You could then assign individual columns to new arrays which could be used as arguments to the table function. This would give you your zero padding for mismatched rows.
Note that if you are using the table function as sending in your arrays in the fashion
table(A,B,C)
you shouldn't receive errors so long as your variables all have an equal number of rows. It sounds like this isn't what you're doing, but without knowing exactly the way you want to arrange your data via some sample code, it's hard to say more.
1 Kommentar
Chelsea
am 19 Feb. 2015
Kategorien
Mehr zu Tables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!