Concatenating Arrays with Different Dimensions
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jordan Means
el 24 de Sept. de 2018
Abierta de nuevo: Walter Roberson
el 22 de Dic. de 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 comentarios
Respuesta aceptada
John D'Errico
el 24 de Sept. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!