reshaping cell containing double arrays

조회 수: 1 (최근 30일)
MiauMiau
MiauMiau 2017년 10월 10일
편집: Guillaume 2017년 10월 10일
Hi,
I have (as an example) the following cell array:
test =
1×4 cell array
[40×1 double] [40×1 double] [40×1 double] [40×1 double]
I want test to be a 1 x 1 cell, containing the double arrays (from left to right) as one double array of dimension 160 x 1. reshape(test,[160,1]) does not work directly here. What can I do?

답변 (3개)

KSSV
KSSV 2017년 10월 10일
편집: KSSV 2017년 10월 10일
test = cell(1,4) ;
for i = 1:4
test{i} = rand(40,1) ;
end
iwant = cell2mat(test) ;
iwant = {iwant(:)} ;
  댓글 수: 2
MiauMiau
MiauMiau 2017년 10월 10일
Is there no quicker way than looping?
Guillaume
Guillaume 2017년 10월 10일
The loop is only to build the demo data.

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


Guillaume
Guillaume 2017년 10월 10일
That's because what you want is not reshaping but a concatenation. (The matrices may not be contiguous in memory):
test = [test{:}]
  댓글 수: 2
MiauMiau
MiauMiau 2017년 10월 10일
That is giving me a 40x4 matrix...?!
Guillaume
Guillaume 2017년 10월 10일
편집: Guillaume 2017년 10월 10일
Oh yes, your vectors are column vectors. Concatenate them vertically then:
test = vertcat(test{:})

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


KL
KL 2017년 10월 10일
편집: KL 2017년 10월 10일
test = cell2mat(test');
this?

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by