How to remove zeros from an element in a cell array
이전 댓글 표시
Hi all,
I have two cell arrays each contain 12 cells, each cell contains different matrix size (31,1) or (30,1) or (28,1), each cell in the array contains a bunch of zeros, and I need to remove these zeros, because it indicates that there is no data at this day
here are an example of my data,
A = {[1 0 1], [2 0 2], ......., [12 0 12]}
B = {[0 2 1], [1 2 0], ........, [12 0 12]}
my purpose is to compare A with B, and to do that I have to remove the zeros and the coincident index in the other cell
A(1,1){2} and B(1,1){2} = []; aslo A(1,1){1} and B(1,1){1}=[];
any suggestions, please??
채택된 답변
추가 답변 (1개)
dpb
2021년 7월 11일
yourarray=cellfun(@(c)c(~-0),yourarray,'UniformOutput',false);
댓글 수: 4
Walter Roberson
2021년 7월 11일
Pretty sure the ~-0 is a typo ;-)
Ebtesam Farid
2021년 7월 11일
편집: Ebtesam Farid
2021년 7월 11일
dpb
2021년 7월 12일
Au contraire --
>> c{:}
ans =
5
3
1
3
0
ans =
2
5
2
1
1
>>
>> c=cellfun(@(c)c(c~=0),c,'UniformOutput',false)
c =
1×2 cell array
{4×1 double} {5×1 double}
>> c{:}
ans =
5
3
1
3
ans =
2
5
2
1
1
>>
Walter Roberson
2021년 7월 12일
Yes, but this is different code; your posted code had c(~-0) not c(c~=0)
카테고리
도움말 센터 및 File Exchange에서 Coordinate Reference Systems에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!