Filter löschen
Filter löschen

Plotting large amounts of txt files then exporting results

1 Ansicht (letzte 30 Tage)
douglas
douglas am 21 Mär. 2012
I am not adept at MATLAB, but I would like help in plotting data from several hundred .txt files and saving the plot results as a .tif or other easily readable file.
How do I import data from such a large amount of files, that share an identical layout, but may have a different amount of rows, then have each txt file plotted and exported as a readable file or pic? I want to save myself having to spend a lot of time doing each txt file individually.

Akzeptierte Antwort

Geoff
Geoff am 22 Mär. 2012
You want to start with the dir command to find the contents of a directory.
indir = 'mydatadir\'; % or / if you are not using windows.
outdir = indir;
mkdir(outdir); % Ensure output dir exists
f = dir([indir '*.txt']);
for n = 1:numel(f)
basename = f(n).name(1:end-4); % remove .txt
infile = [indir f(n).name]
outfile = [outdir basename '.tiff'];
% now load the file and plot your chart as you would normally
%[TODO]
% save the chart (in this case it's gcf, but could be your own figure
print( gcf, '-dtiff', outfile );
end
This will output an image for each file, using the same base filename: ie data03.txt --> data03.tiff
Look at the documentation for print. I used -dtiff, but you could spit out a jpeg, png, or eps instead.
You'll probably want to change various parameters on your figures to set the size. Play around, and enjoy.

Weitere Antworten (0)

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by