How to remove zeros from an element in a cell array
Afficher commentaires plus anciens
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??
Réponse acceptée
Plus de réponses (1)
dpb
le 11 Juil 2021
yourarray=cellfun(@(c)c(~-0),yourarray,'UniformOutput',false);
4 commentaires
Walter Roberson
le 11 Juil 2021
Pretty sure the ~-0 is a typo ;-)
Ebtesam Farid
le 11 Juil 2021
Modifié(e) : Ebtesam Farid
le 11 Juil 2021
dpb
le 12 Juil 2021
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
le 12 Juil 2021
Yes, but this is different code; your posted code had c(~-0) not c(c~=0)
Catégories
En savoir plus sur Coordinate Reference Systems dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!