Extract Data From .txt file

2 ビュー (過去 30 日間)
Nicholas Kavouris
Nicholas Kavouris 2022 年 3 月 10 日
回答済み: Gagan Agarwal 2023 年 11 月 16 日
Hello, I have a text output from a terminal program which reads data from a PID controller as shown below. How do I take the relevant data terms from the text and properly place them into respective arrays? Relevant data is essentially each numerical value
LOW FUEL EMPTY: 0 LOW FUEL UV: 217285
ERROR CODE: 0
selectiveModeSelect: 0
Set: 2322-210 = 2112 TempC: 179 StartTempC: 3 MaxTempC: 228 UserInputC: 0
adjusted_temp_c_display: 1935
StartTempC: 3 MaxTempC: 228 UserInputC: 0
blockNewSetpoints: 0
FlameStarted: 1
temp_threshold_reached: 1 ThresholdC: 183
Shutdown State 0 Duration 470/480
Glow plug: 0 Glow plug cycles: 1
temperature_reached: 1 temp_treshold_reached 1
Auger PWM: 128/255 RPM: 143 CCW: 1
AugerMaxReady 1
AugerReversed 0
Fan PWM: 255 RPM: 3780
PB: 60 Tu: 360 TablePtr: 42
P: -45
I: 756
D: -15
u: 695
  4 件のコメント
Nicholas Kavouris
Nicholas Kavouris 2022 年 3 月 10 日
FID=fopen('File_name','w');
A=fscanf(FID,'%c');
fclose(FID);
Kp=regexp(A,'P:[+-]?\d+','match');
P=str2double(Kp)
So to begin would code look something similar? unsure of of the expression term as all values will be integers
Walter Roberson
Walter Roberson 2022 年 3 月 10 日
FID=fopen('File_name','w');
That would ask to creat a new file named File_name or erase the content of an existing file with that name.
The file would be empty, and fscanf() would produce no data.
I suggest you consider fileread() or readlines()

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

回答 (1 件)

Gagan Agarwal
Gagan Agarwal 2023 年 11 月 16 日
Hi Nicholas
I understand that you are trying to numerical value from a text file. This can be achieved by using 'regexp' function of MATLAB . This function is helpful for extracting specific patterns from text data, including the numerical values.
For additional information regarding 'regexp' function please refer to the following documentation:
I hope it helps!

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by