Borrar filtros
Borrar filtros

Create a Single Array From 3 different one

1 visualización (últimos 30 días)
Fabio Taccaliti
Fabio Taccaliti el 29 de Abr. de 2022
Comentada: Jan el 2 de Mayo de 2022
Hello,
I have 3 arrays x, y and z (each 14x4) and I want to create from these an array tot (56x3).
It should be composed taking for the first cell, the first element of array x, in the second one, the first element of array y and in the third one, the first element of array z and so on for all the elements in the sub-arrays (going row by row), how can I do it?
Basically the sub-arrays contains all the coordinated of a set of point (divinded in x, y and z) and I want to create an array with all the points and the different coordinates on the 3 columns (x, y and z).
I think I have to use 3 loops for each array, but how?
Thanks in advance

Respuestas (1)

Jan
Jan el 29 de Abr. de 2022
Editada: Jan el 29 de Abr. de 2022
I'm not sure what "going row by row" means. Maybe
x = rand(14, 4);
y = rand(14, 4);
z = rand(14, 4);
xt = x.';
yt = y.';
zt = z.';
result = [xt(:), yt(:), zt(:)]
% or:
result = [x(:), y(:), z(:)]
  2 comentarios
Fabio Taccaliti
Fabio Taccaliti el 29 de Abr. de 2022
Editada: Fabio Taccaliti el 29 de Abr. de 2022
Hi Jan, thanks for the answer.
With row by row I mean that after I finish to concatenate the fourth element of array x, y and z the algorithm should go in the second row and start again with the concatenation and so on. Let me know if now is more clear.
Regarding the code that you posted I get the following error, I think is due to the semicolon instead of comma
Dimensions of arrays being concatenated are not consistent.
Jan
Jan el 2 de Mayo de 2022
@Fabio Taccaliti: The code I have posted does not produce this error. Then the cause of the problem must be a part of your code. If you post your code, it would be possible to fix the problem.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by