필터 지우기
필터 지우기

merge cells into a single one

조회 수: 2 (최근 30일)
Qifan
Qifan 2014년 7월 28일
댓글: dpb 2014년 7월 28일
I have a number of cells h={cell1; cell2; cell3;...cell100}, each cell contains one row but multiple columns (1*n, n varies across cells). Now I want a single cell g contain one row and the sum(n) columns. The basic method is g=[h(1) h(2) h(3) ... h(100)]. Since there are so many cells, it is not convenient to type all. Is there any effective way to make this by exploiting the index? Many thanks.
  댓글 수: 1
Qifan
Qifan 2014년 7월 28일
A simple transpose function works for cell array.

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 28일
If your data looks like
v={1:3 10:20 4 100:105}
out=cell2mat(v)
  댓글 수: 1
Qifan
Qifan 2014년 7월 28일
Thanks, but actually I have h={1:3; 10:20; 4; 100:105} and I want to have the v you mentioned. The basic way is just too inconvenient to type.

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


dpb
dpb 2014년 7월 28일
편집: dpb 2014년 7월 28일
c={cell2mat(c)};
...h={1:3; 10:20; 4; 100:105}
Well, you didn't say that in the original. But the answer is the same excepting you must transpose c --
c={cell2mat(c.')};
I returned it as a cell, Azzi just left it as the array; your choice of which you want.
  댓글 수: 2
Qifan
Qifan 2014년 7월 28일
The transpose function works, but thanks for the help.
dpb
dpb 2014년 7월 28일
.' is the transpose function as was pointed out that's what you needed to do once you revealed you had a column array instead of row. The ' operator is the complex conjugate transpose; for the cell array orientation the accidental use of ' instead of .' does no harm as it doesn't operate on the cell content, but it's a poor habit to get into.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by