필터 지우기
필터 지우기

Why error using cell2mat ?

조회 수: 6 (최근 30일)
saharsahar
saharsahar 2013년 7월 19일
Hi all, I have a 309 * 5956 cell array of same type and same length. however most of the elements are empty.
However using cell2array to convert this matrix to numerical it gives me error as:
cell2mat(all_i_dis)
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 79)
m = cat(1,m{:});
any idea is highly appreciated.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 19일
A={ 1 , 2 ; [], 4};
cell2mat(A);
The result
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 87)
m = cat(2,m{:});
To use cell2mat, all cells must be the same size and same class
  댓글 수: 3
saharsahar
saharsahar 2013년 7월 19일
I know the way through a loop like
for n=1:length(mycellarray)
if isempty(mycellarray{n})
mycellarray{n}=0;
end
end
but is there any other efficient way instead of loop?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 19일
편집: Azzi Abdelmalek 2013년 7월 19일
A(cellfun('isempty',A))={0}
%or
A(cellfun('isempty',A))={nan}

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by