필터 지우기
필터 지우기

Remove rows usig cellfun

조회 수: 3 (최근 30일)
djr
djr 2015년 1월 31일
답변: Star Strider 2015년 2월 1일
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