Clear Filters
Clear Filters

Plotting large amounts of txt files then exporting results

1 view (last 30 days)
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.

Accepted Answer

Geoff
Geoff on 22 Mar 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.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!