Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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)

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 3 de Jul. de 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)

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by