How to combine n cell arrays into one giant one?

조회 수: 6 (최근 30일)
Susan
Susan 2021년 6월 7일
편집: Susan 2021년 6월 7일
Hello,
I have a 12-by-190 cell array dataset, each contains either a 1-by-504 cell array or a 1-by-336 cell array. Each of these cell array contains a vector of size of either 600-by-1 or 300-by-1.
As for labels, I have a 12-by-190 cell arrays that each cell contains either a 1-by-504 cell array or a 1-by-336 cell array.
I'd like to concatenate all of the cells together into one giant cells (or preferably a giant matrix) and a corresponding array of labels.
How can I do that?
Thanks in advance

답변 (1개)

SALAH ALRABEEI
SALAH ALRABEEI 2021년 6월 7일
I think you need to loop a bit since you have cells of cells. Let A and B are ur outer cell matrices, data and labels
% Try this
NA=[];
NB =[];
for i = length(A)
a = [A{i}{:}];
b = [B{i}{:}];
NA = [NA,a(:)];
NB = [NB,b(:)];
end
  댓글 수: 2
SALAH ALRABEEI
SALAH ALRABEEI 2021년 6월 7일
if you get an error try this instead [NA;a(:)];
Susan
Susan 2021년 6월 7일
편집: Susan 2021년 6월 7일
Thank you so much for your response. I added one more loop to go over 12 cells but it seems it takes forever
NA=[];
NB =[];
for i = 1: size(A,1)
for j = 1: size(A,2)
a = [A{i}{:}];
b = [B{i}{:}];
NA = [NA;a(:)];
NB = [NB;b(:)];
end
end
any idea? Moreover NA = [NA,b(:)] gives me error and using ";" doesn't make sense with my data.
Thanks again

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by