How do I pull the specific data I need from a text file?

3 次查看(过去 30 天)
I have an output file from which I am trying to pull specific data and plot it. I added comments in the format "% FIRST LINE OF X VALUES" to the file for the sake of people looking at my question being able to see which values I am trying to pull, however these comments are not in the actual output file. I am trying to pull two specific blocks of values from this file, one of "x" values and one of "y" values, and plot them and while I know how to plot the data once I've extracted it, I am not sure how to pull the data correctly from the file. For those trying to help, the data I need to pull is near the end of the attached file. Any ideas are greatly appreciated!

回答(1 个)

Harish Ramachandran
You can probably write your own parser and go through each line until you stumble upon the 'x' and 'y' parameters. Collect the data in a vector and then proceed to plot the 'x' and 'y' values.
A sample line parser for the txt file.
file = fopen('mctan.txt');
line = fgetl(file);
for i=1:6
if any(line == 'x values')
disp("x values need to be stored")
elseif any(line == 'y values')
disp("y values need to be stored")
line = fgetl(file);
end
fclose(file);

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by