Effacer les filtres
Effacer les filtres

Create a Single Array From 3 different one

1 vue (au cours des 30 derniers jours)
Fabio Taccaliti
Fabio Taccaliti le 29 Avr 2022
Commenté : Jan le 2 Mai 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

Réponses (1)

Jan
Jan le 29 Avr 2022
Modifié(e) : Jan le 29 Avr 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 commentaires
Fabio Taccaliti
Fabio Taccaliti le 29 Avr 2022
Modifié(e) : Fabio Taccaliti le 29 Avr 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 le 2 Mai 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by