how can I tell MATLAB to add a NaN if the size of concatenation is not consistent?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ali Almakhmari
am 18 Jan. 2023
Beantwortet: Dyuman Joshi
am 18 Jan. 2023
Lets say I have two matrices: A = [2,2;3;3] and B = [4,4,4;5,5,5]
I was trying to concatnate them by doing: C = [A; B]
But MATLAB threw an error saying that the dimensions are not consistent.
Now whats an easy way to fix this? The result that I would like from the example I gave previously is: C = [2,2,NaN; 3,3,NaN; 4,4,4; 5,5,5]
1 Kommentar
Florian Rössing
am 18 Jan. 2023
You could write your own function that does length matching before concatenating. Appart from that, no Idea
Akzeptierte Antwort
Dyuman Joshi
am 18 Jan. 2023
A = [2,2;3,3];
B = [4,4,4;5,5,5];
A=padarray(A,[0 1],nan,'post')
C=[A;B]
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!