# how can I tell MATLAB to add a NaN if the size of concatenation is not consistent?

3 vues (au cours des 30 derniers jours)
Ali Almakhmari le 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 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Florian Rössing le 18 Jan 2023
You could write your own function that does length matching before concatenating. Appart from that, no Idea

Connectez-vous pour commenter.

### Réponse acceptée

Dyuman Joshi le 18 Jan 2023
A = [2,2;3,3];
B = [4,4,4;5,5,5];
A = 2×3
2 2 NaN 3 3 NaN
C=[A;B]
C = 4×3
2 2 NaN 3 3 NaN 4 4 4 5 5 5
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by