フィルターのクリア

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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by