Plotting large amounts of txt files then exporting results
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!