Concatenating Arrays with Different Dimensions
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jordan Means
le 24 Sep 2018
Rouvert : Walter Roberson
le 22 Déc 2018
I'm trying to concatenate these arrays with one line of code. How do I go about doing that?
The final array was supposed to be 3 x 4. I tried using the cat command, but because the dimensions are different, I had trouble doing it.
x = rand(1,3)
x = 10*x
x = round(x)
y = rand(1,3)
y = 10*y
y = round(y)
z = rand(1,4)
z = 10*z
z = round(z)
q = rand(2,1)
q = 10*q
q = round(q)
0 commentaires
Réponse acceptée
John D'Errico
le 24 Sep 2018
You can want to do all sorts of things that are not possible to do.
But you cannot create a double precision array that has a varying amount of elements in each row or column. Arrays are RECTANGULAR things. So an array that has 3 elements in one row, and 4 elements in another will fail to work. It is invalid syntax to try to construct such a thing. Wanting is insufficient, unless of course, you will also decide to rewrite MATLAB from scratch. (Have fun with that.)
You COULD decide to pad zeros, or perhaps NaNs to some of those vectors as necessary, so they are all the same lengths. Or, you could use a cell array to store the vectors.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!