필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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)

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 3일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by