필터 지우기
필터 지우기

Create a Single Array From 3 different one

조회 수: 1 (최근 30일)
Fabio Taccaliti
Fabio Taccaliti 2022년 4월 29일
댓글: Jan 2022년 5월 2일
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

답변 (1개)

Jan
Jan 2022년 4월 29일
편집: Jan 2022년 4월 29일
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
Fabio Taccaliti
Fabio Taccaliti 2022년 4월 29일
편집: Fabio Taccaliti 2022년 4월 29일
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 2022년 5월 2일
@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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by