delete rows in a cell array
Mostra commenti meno recenti
having a cell array containing in 1st column a name of a country and in next column values, how can I delete rows containing 1 or more zeros values?
1 Commento
Stephen23
il 29 Gen 2019
@Anastasia Anastasiadou: please upload your data in a .mat file by clicking the paperclip button.
Risposta accettata
Più risposte (2)
Omer Yasin Birey
il 29 Gen 2019
Modificato: Omer Yasin Birey
il 29 Gen 2019
Lets say your cell array's variable name is 'a'
a = a(all(cellfun(@(x)x~=0,a),2),:);
5 Commenti
Anastasia Anastasiadou
il 29 Gen 2019
madhan ravi
il 29 Gen 2019
you mean if there is any zero in the row you want to delete it?
Anastasia Anastasiadou
il 29 Gen 2019
Omer Yasin Birey
il 29 Gen 2019
That should work
remZeros = a(all(cellfun(@(x)x~=0,a),2),:);
remZeros(2:end+1,:) = remZeros(1:end,:);
remZeros(1,:) = a(1,:);
Anastasia Anastasiadou
il 29 Gen 2019
KSSV
il 29 Gen 2019
Let A be your matrix with size (m,n)
idx = A==0 ;
A(sum(A,2)~=n,:) = [] ;
2 Commenti
madhan ravi
il 29 Gen 2019
? OP has mentioned it’s a cell array not a matrix.
Anastasia Anastasiadou
il 29 Gen 2019
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
