How to read and process text file

조회 수: 2(최근 30일)
Altemur Çelikayar
Altemur Çelikayar 2021년 5월 2일
댓글: Scott MacKenzie 2021년 5월 2일
Hello, I need to read this kind of text files which have 5000-7000 row.
Frame number 565
First frame 1
Point frequency 100
Analog frequency 1000
Time RFCR RECR
s V V
0 4.76074e-005 0.000181885
0.001 2.86865e-005 0.000102386
0.002 3.75366e-005 3.8147e-005
0.003 3.11279e-005 2.47192e-005
0.004 0 -0.000175323
0.005 -4.42505e-006 -0.000256348
0.006 -1.2207e-006 -0.000149689
0.007 -5.37109e-005 -1.60217e-005
0.008 -5.02014e-005 0.000109711
0.009 -5.52368e-005 6.50024e-005
0.01 -1.77002e-005 4.42505e-005
0.011 -1.98364e-006 -7.78198e-005
0.012 1.58691e-005 -0.000232697
0.013 -1.52588e-005 -0.000134735
0.014 -5.40161e-005 -3.00598e-005
0.015 -2.04468e-005 0.000126038
0.016 -1.26648e-005 3.49426e-005
0.017 3.05176e-007 -0.000101624
0.018 6.56128e-006 1.00708e-005
0.019 1.78528e-005 5.79834e-005
0.02 4.71497e-005 -2.92969e-005
0.021 4.48608e-005 -4.71497e-005
0.022 1.14441e-005 -0.000177612
I need to take average of s, RFCR, RECR values and print like that: [filename,0.15,3.569e-05,0.0001528]
How can i do that. Can you help

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 5월 2일
filename = 'testdata.txt'; % data from question
T = readtable(filename);
s_mean = mean(T.Time);
RFCR_mean = mean(T.RFCR)
RECR_mean = mean(T.RECR);
fprintf('[%s,%.3f,%e,%f]\n', filename, s_mean, RFCR_mean, RECR_mean);
Output:
[testdata.txt,0.011,9.287678e-08,-0.000028]
  댓글 수: 2
Scott MacKenzie
Scott MacKenzie 2021년 5월 2일
You're welcome.

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

추가 답변(0개)

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by