Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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!

Risposte (1)

Harish Ramachandran
Harish Ramachandran il 19 Feb 2018
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);

Categorie

Scopri di più su Large Files and Big Data in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by