How to extract a number from .prn file
19 views (last 30 days)
Show older comments
Tsuwei Tan
on 25 Jun 2018
Answered: Walter Roberson
on 26 Jun 2018
May I ask how to extract certain number from .prn file? For instance, I have a file called HLA31_Shru00070.prn which is contained in the .zip file how do I extract a particular number which is mode 2 group speed its value is 1471.158022 as attached picture?
I have numerous .prn files that I have to extract its corresponding group speed, such as HLA31_Shru00055.prn HLA31_Shru00056.prn ... HLA31_Shru00070.prn HLA31_Shru00071.prn ...
Understood that I will need a for loop to do it, may I ask how to extract numerous files simultaneously? Do I need to rename the prn files so Matlab can read it?
Thank you!!
2 Comments
Walter Roberson
on 25 Jun 2018
Is the data always at the same line number in the file?
"Do I need to rename the prn files so Matlab can read it?"
No, that will not be necessary, but exactly how easy it is will depend upon the answer the question about line number.
Accepted Answer
Walter Roberson
on 26 Jun 2018
filename = 'LHA31_Shru_00070.prn';
S = fileread(filename);
GStr = regexprep(S, {'^.*GROUP SPEED.*?$', '^.*?copied.*'}, {'', ''}, 'lineanchors');
Now GStr should contain just the lines of the GROUP SPEED table. You could then
GSdata = cell2mat( textscan(GStr, '%f%f%f%f%f', 'CollectOutput', true) );
and GSdata would be a numeric array that you could extract any desired parts from.
The process would be easier still if the exact line number of the GROUP SPEED header was known.
0 Comments
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!