Remove rows usig cellfun

3 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2015-2-1
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 个)

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by