Trying to remove range of negative numbers from a specific column of multiple rows

1 view (last 30 days)
I am trying to remove negative numbers < -13.5 from a text file from column 14 of each row (text file attached; within21rm.txt). I am using Idx=cellfun, but it isn't recognizing that I need to set a restriction on negative numbers.
Below is my code:
clear all
fidi = fopen('within21rm.txt','rt');
Glxc = textscan(fidi, '%s', 'Delimiter','|');
frewind(fidi)
Glxcs = textscan(fidi, '%s', 'EndOfLine','\r\n');
fclose(fidi);
dlen = 18*fix(length(Glxc{:})/18); % Set Row Length
Glxcr = reshape(Glxc{:}(1:dlen), 18, [])'; % Reshape & Transpose
Idx = cellfun(@(x) str2num(x) < -13.5, Glxcr(:,14), 'Uni',0); % Find Rows With Col14 < -13.5
LIdx = logical(cell2mat(Idx)); % Logical Array From Cell
NewGlxc = Glxcs{:}(LIdx,:); % Rows Of New Array
fido = fopen('faintgrm.txt','wt')
fprintf(fido, '%s\n', NewGlxc{:});
fclose(fido)

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 3 Jul 2015
dlen = 18*fix(length(Glxc{:})/18); % Set Row Length
Glxcr = reshape(Glxc{:}(1:dlen), 18, [])'; % Reshape & Transpose
LIdx=str2double(Glxcr(:,14))<-13.5
NewGlxc = Glxcs{:}(LIdx,:); % Rows Of New Array
fido = fopen('faintgrm.txt','wt')
fprintf(fido, '%s\n', NewGlxc{:});
fclose(fido)

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!