Create a Single Array From 3 different one

1 view (last 30 days)
Fabio Taccaliti
Fabio Taccaliti on 29 Apr 2022
Commented: Jan on 2 May 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

Answers (1)

Jan
Jan on 29 Apr 2022
Edited: Jan on 29 Apr 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 Comments
Fabio Taccaliti
Fabio Taccaliti on 29 Apr 2022
Edited: Fabio Taccaliti on 29 Apr 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 on 2 May 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.

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!