Remove rows usig cellfun
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Star Strider
il 1 Feb 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!