how to read .sts file in matlab?

조회 수: 4 (최근 30일)
sandy
sandy 2013년 9월 5일
hi..i have .sts file(45000). i need to read this files in a loop and append them into an excel file. in each .sts file,it contains data like below,
SAMPLE_20130606_0006 0 +6.470299E+0 +4.009076E+0 +1.699308E+1 +1.095633E+0
SAMPLE_20130606_0016 0 +6.938715E+0 +2.954977E+0 +1.125970E+1 +1.396087E+0
SAMPLE_20130606_0026 0 +8.297382E+0 +4.155266E+0 +2.333013E+1 +1.611527E+0
SAMPLE_20130606_0036 0 +8.837934E+0 +5.234266E+0 +1.352240E+1 +1.407429E+0
SAMPLE_20130606_0046 0 +8.098710E+0 +3.642447E+0 +1.205176E+1 +1.683126E+0
how to read this file in a loop and save in excel format?

채택된 답변

Walter Roberson
Walter Roberson 2013년 9월 5일
xlswrite() for the file writing.
When you read the data, do you want all fields (including the text line), or do you only want the numbers? Perhaps only the last 4 numbers?
If you want everything, just broken out into fields, the consider using fileread() to read the file, and regexp() with 'split' option to break it into fields.
  댓글 수: 3
Walter Roberson
Walter Roberson 2013년 9월 10일
Use fullfile() to construct the input and output file names. xlswrite() will be perfectly happy to be given a file name in a different directory.
Walter Roberson
Walter Roberson 2013년 9월 10일
indir = 'INPUT';
outdir = 'OUTPUT';
finfo = dir(fullfile(indir, '*.sts'));
massoutput = {};
for K = 1 : length(finfo);
thisfilename = fullfile(indir, finfo(K).name);
sts = fileread(thisfilename);
t = regexp(regexp(regexprep(sts, ' *\n *$', ''), ' *\n', 'split'), '\s+', 'split');
massoutput{K} = vertcat(t{:});
end
massoutput = vertcat(massoutput{:});
thisfilename = fullfile(outdir, 'allsts.xls');
xlswrite(thisfilename, massoutput);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by