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

5 ビュー (過去 30 日間)
Jessica Maxson
Jessica Maxson 2018 年 1 月 16 日
回答済み: Harish Ramachandran 2018 年 2 月 19 日
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
Harish Ramachandran 2018 年 2 月 19 日
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 Center および File ExchangeLarge 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