How can I extract infroamtion from a header's file (text file)?

9 次查看(过去 30 天)
I want extract information from a header file (see attachment). For instance I would like to save in an array or in variables the information such as, time, date, BeamVoltage, Filament, Temp, etc... so I can use these values later on or simply send them to a text box on a GUI.
I have tried several things but nothing really works for all since the format is not uniform at all, the information of interest sometimes comes after a ':' or a '=' or simple a ' '... Please help!!!.
Thanks, Alex

回答(1 个)

Radha Krishna Maddukuri
First of all, there is no direct ways for reading values with different delimiters like '=' ':' 'space', etc.,
However, readtable is a good function for reading the values that you intend to. The second example in the following documentation is relevant to your use case.
However a slight modification is required to your file.
For example: create a file A.txt:
Beam Voltage (-kV) = 13.000
Filament (W) = 4.052
Wehnelt (-V) = 400.00
Cond. (-kV) = 8.685
CenterX1 (V) = 23.7
CenterY1 (V) = -47.9
Objective (OctupoleX = 0.0000
OctupoleY = 0.0000
Angle (deg) = 0.00
Stig = 0.00
Then navigate to the folder containing A.txt in MATLAB and execute the following command in MATLAB Command Window:
>> readtable('A', 'delimiter', '=')
You will be able to read the required data.
For automating the modification of TEXT files, the following MATLAB Answer might be helpful.
I hope this helps you.

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by