Remove non-empty and zeroed cells from cell array.

조회 수: 9 (최근 30일)
lucksBi
lucksBi 2017년 6월 13일
댓글: lucksBi 2017년 6월 13일
hey
i have cell array like this:
myArray= {[],1,1,0.1,0.1;[],[],1,1,0.2;[],[],[],[],1;0.3,[],[],[],0.6;0.4,[],[],0.3 [];0.6,0.33,0.12,0.67,0.13;1,0.62,0.11,0.31,1;[],[],[],1,[]}
how to remove empty and zeroed cells from this array for each row. i have tried following which worked fine if i apply it on each row separately. but how to do it for whole array.
newArray=reshape(myArray(~cellfun(@isempty,myArray)),1,[]);
Thanks
  댓글 수: 3
Matt J
Matt J 2017년 6월 13일
how to remove empty and zeroed cells from this array for each row
Doing so would result in rows of different lengths. What do you want to replace the cells with so that it can maintain its rectangular shape?
lucksBi
lucksBi 2017년 6월 13일
Can i get it in a cell array in which each cell contains non-zero elements from each row?

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 6월 13일
A = myArray';
[~,ii] = find(~cellfun(@isempty,A));
out = accumarray(ii,[A{:}]',[],@(x){x'})

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by