How to read the 3rd column in a line and skip if value is greater than E+37

4 ビュー (過去 30 日間)
Snehalatha
Snehalatha 2014 年 4 月 5 日
コメント済み: Snehalatha 2014 年 4 月 6 日
Hello all,
I have a text file with below given format.
16.Mrz.14 10:12:34
16.Mrz.14 10:12:37 -01,22522E-09
16.Mrz.14 10:12:40 -00,90903E-09
16.Mrz.14 10:12:42 -00,72633E-09
16.Mrz.14 10:12:45 -00,59084E-09
16.Mrz.14 10:12:48 -00,50685E-09
16.Mrz.14 10:12:50 -00,42215E-09
16.Mrz.14 10:12:53 -00,38118E-09
16.Mrz.14 10:12:55 -00,32913E-09
16.Mrz.14 10:12:58 -00,29374E-09
16.Mrz.14 10:13:00 -00,25394E-09
16.Mrz.14 10:13:03 +9,900000E+37OADC,+1629586.578736secs,+12454976RDNG#
16.Mrz.14 10:13:06 -000,0389E-09
16.Mrz.14 10:13:09 -000,2374E-09
16.Mrz.14 10:13:13 -000,1355E-09
I have a code written to skip incomplete lines using number of columns but the same logic didn't work when i tried skipping the row with E+37. Could someone tell me how to skip all the rows with the format 16.Mrz.14 10:13:03 +9,900000E+37OADC,+1629586.578736secs,+12454976RDNG? Looking forward to your help
  2 件のコメント
Walter Roberson
Walter Roberson 2014 年 4 月 5 日
Do the unwanted lines always end in "#" ?
Snehalatha
Snehalatha 2014 年 4 月 6 日
Yes they always have #

サインインしてコメントする。

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 5 日
fid = fopen('file.txt');
res={};
while ~feof(fid)
res{end+1,1} =fgetl(fid);
end
fclose(fid);
res(~cellfun('isempty',regexp(res,'E\+37','match')))=[]
  1 件のコメント
Snehalatha
Snehalatha 2014 年 4 月 6 日
Hallo i tried integrating this in my code but doesn't seem to work. can you tell me whats wrong. My code is as below
% Interactive file chooser
fprintf('\n');
fprintf('Begin Interactive Plotting Script(%s)\n',datestr(now));
[fileName,pathName]=uigetfile('*.txt','Select a measurement file to load.');
fullPath=[pathName,fileName];
fprintf('The file you chose was %s\n',fullPath);
% Interactively input the measurement interval
inpBuff = inputdlg('Enter Measurement Interval:', 'Value', [1 50]);
measurementInterval=str2double(inpBuff{:});
fprintf('The measurement interval is %f\n',measurementInterval);
%% Read columns of data as strings:
% For more information, see the TEXTSCAN documentation.
formatSpec = '%9s%9s%s%[^\n\r]';
%% Open the text file.
fileID = fopen(fullPath,'r');
%% Skip incomplete lines and Read columns of data according to format string.
t=fgetl(fileID);
while ischar(t)
if size(t,2)<=19
% Skips empty lines
else
dataArray = textscan(fileID, formatSpec, 'Delimiter','', 'WhiteSpace', '', 'ReturnOnError', false);
end
t=fgetl(fileID);
end
dataArray(:,4)=[];
%% Close the text file. fclose(fileID);
Could you please help me where to integrate it and tell how it works. I am fairly new to matlab

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by