Azzera filtri
Azzera filtri

Concatenating Arrays with Different Dimensions

2 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

John D'Errico
John D'Errico il 24 Set 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.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by