Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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)

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 3 Juil 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)

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by