Concatenate a column of cells into a single array

조회 수: 1 (최근 30일)
Corey Pew
Corey Pew 2019년 4월 15일
댓글: Corey Pew 2019년 4월 16일
Hello,
I have a cell containing multiple arrays that I want to concatenate into a single array such that X{1}, X{2},... are all each a 100x1 double. I am hoping for a non looping solution that will put them all together into a single array that is 100xlength(X). I have tried using cat(), vertcat() and others but keep getting the error that 'dimensions of arrays being concatenated are not consistent.' Any help is greatly appreciated, thanks!
  댓글 수: 1
Corey Pew
Corey Pew 2019년 4월 16일
Update, I mistyped my format. My cell array is actually a column of cells such that:
>> X = { rand(4,1); rand(4,1); rand(4,1) }
X =
3×1 cell array
{4×1 double}
{4×1 double}
{4×1 double}
Both answers below work if you first transpose X:
>> X = X';
Thank you for the help!

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

채택된 답변

madhan ravi
madhan ravi 2019년 4월 15일

추가 답변 (1개)

per isakson
per isakson 2019년 4월 15일
cat() is also a possiblity
Y = cat( 2, X{:} );
Example
>> X = { rand(4,1), rand(4,1), rand(4,1) }
X =
1×3 cell array
{4×1 double} {4×1 double} {4×1 double}
>> cat( 2, X{:} )
ans =
0.8147 0.6324 0.9575
0.9058 0.0975 0.9649
0.1270 0.2785 0.1576
0.9134 0.5469 0.9706
>>
  댓글 수: 1
Corey Pew
Corey Pew 2019년 4월 16일
Thank you for the excellent example. Seeing it this way helped me realize I needed to transpose X to get the desired result.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by