cover cell array into vector

조회 수: 1 (최근 30일)
Ana-Maria Pistea
Ana-Maria Pistea 2020년 5월 18일
댓글: Ana-Maria Pistea 2020년 5월 18일
hi all, I have this cell array and I want to conver it into a vector. The problem is that cell2mat will remove the empty cells and I want to keep them as = ' '.
Then I need to build again the cell array from the resulted vectore.
Any help would be appreciated.
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2020년 5월 18일
You can't store empty '' or [] in numerical array. The best you can do is to replace it with zero or nan

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

채택된 답변

Stephen23
Stephen23 2020년 5월 18일
편집: Stephen23 2020년 5월 18일
Numeric arrays do not have empty elements: every element has one value.
But you can easily store the sizes and recreate the cell array:
>> C = {[0;0],[],[],[0,1,2,3;0,0,0,0]};
>> S = cellfun('size',C,2);
>> M = cell2mat(C);
Recreate (strictly speaking the empty matrices have different sizes compared to those in C):
>> D = mat2cell(M,2,S);
  댓글 수: 1
Ana-Maria Pistea
Ana-Maria Pistea 2020년 5월 18일
This works. Thx a lot!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by