Hi,
Having (for instance) a 1x3 cell which contains in each entry a double array of a different size. For instance:
cell(1) = 1x2 double cell(2) = 1x10 double cell(3) = 1x6 double
I want to convert any such cell (hence with somewhat generic code), to a cell with one row containing all the elements of the double arrays one after another (in this example it would be a 1x18 cell). How can I do that?

 채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 1일

1 개 추천

cell2mat(TheCell)

댓글 수: 3

MiauMiau
MiauMiau 2017년 7월 1일
편집: MiauMiau 2017년 7월 1일
But I want a (in this example 1x18) cell at the end, is there no faster way than cell2mat and then back to cell?
Well, technically you could use
temp = horzcat(TheCell);
L = length(temp);
result = cell(1,temp);
for K = 1 : L; result{K} = temp(L); end
That might be slightly faster than
num2cell(cell2mat(TheCell))
Your question is a bit ambiguous as to whether you want a single cell entry with a 1 x 18 double vector in it, or if you want a 1 x 18 cell vector each with one double.
MiauMiau
MiauMiau 2017년 7월 1일
The later, and your code works fine!:) Thank you

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2017년 7월 1일

댓글:

2017년 7월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by