Plotting large amounts of txt files then exporting results

조회 수: 4 (최근 30일)
douglas
douglas 2012년 3월 21일
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.

채택된 답변

Geoff
Geoff 2012년 3월 22일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by