MATLAB Answers

0

How to put different arrays in one big array?

Meshooo 님이 질문을 제출함. 31 Jan 2017
최근 활동 Andrei Bobrov 님이 답변함. 2 Feb 2017
Dear all,
I have three arrays with different lenght
A = [1,2,3,4,5,6,7,8,9,10];
AA = A';
B = [10,20,30,40,50,60,70,80,90];
BB = B';
C = [10,20,30,40,50,60,70,80,90,100,110];
CC = C';
I want to put them all in one big array next to each other, so they appear like this
All =
1 10 10
2 20 20
3 30 30
4 40 40
5 50 50
6 60 60
7 70 70
8 80 80
9 90 90
10 100
110
Because of size difference I couldn't use this
All(:,1) = AA;
All(:,2) = BB;
All(:,3) = CC;
Any idea how to do solve it?
Thank you,
Meshoo

  댓글 수: 0

로그인 to comment.

답변 수: 2

Answer by Honglei Chen
on 31 Jan 2017

You need to either pad them into same size or you can use cell array
AllArray = {AA, BB, CC}
HTH

  댓글 수: 1

Thank you, but if you type AllArray in the command window then you will be able to get those arrays. Also you can't write it to excel file.
However, I solved it in this way:
A=[1; 2; 3; 4; 5];
B=[1; 2; 3; 4; 5; 6; 7; 8];
C=[1; 2; 3];
All = A
All(1:numel(B),2) = B
All(1:numel(C),3) = C

로그인 to comment.


Answer by Andrei Bobrov
on 2 Feb 2017

D = {A,B,C};
s = cellfun(@numel,D);
m = max(s);
n = numel(D);
out = zeros(m,n);
for ii = 1:n
out(1:s(ii),ii) = D{ii};
end

  댓글 수: 0

로그인 to comment.



Translated by