Remove rows usig cellfun
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
djr
le 31 Jan 2015
Réponse apportée : Star Strider
le 1 Fév 2015
Hello,
Neg is 1x8 cell. Each cell column has 101096 data, i.e. length(Neg{1,1}) is 101096. All data are numbers. I need to find the following values: 999.9, 99.9 or 99999 and delete that row in all cell columns.
To do a), I tried this:
fid = fopen('Neg.csv');
Neg = textscan(fid, '%*d %d %d %d %d %*d %*d %*d %d %f %f %f %*[^\n]', ...
'HeaderLines', 1, 'Delimiter', '\t');
fclose(fid);
clear ans fid
Neg(cellfun(@(x) any(x == 999.9), Neg)) = [];
or
Neg(any(cellfun(@(x) any(x==999.9),Neg),2),:) = [];
or
Neg(cellfun(@(x) x==999.9, Neg, 'UniformOutput', false), :) = [];
but it doesn't work. I tried it for 999.9 only because I don't know how to specify several conditions (99999 or 999.9 or 99.9).
Attached is a sample of the file.
Please could you help me with this?
Thanks in advance!
DjR
0 commentaires
Réponse acceptée
Star Strider
le 1 Fév 2015
It seems to be all numeric, so use cell2mat and do everything on it as a double array.
You can get a logical array of the indices that meet your requirements with:
Idx = cellfun(@(x) (x == 99.9), Neg, 'Uni',0);
but you can’t go farther with cell functions.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Data Preparation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!