Filter löschen
Filter löschen

plotting with for loop for many text files

1 Ansicht (letzte 30 Tage)
douglas
douglas am 6 Apr. 2012
Hello all, I am tyring to use MATLAB at work to plot about 800 text files, all having identical column format (so the same textscan function on each one) and the code below adequately plots ONE of these text files for me, my question is how would I model my for loop to load each text file one by one and spit out a different tiff image in my results folder. These text files all share a similar name (MT_00050-000 through MT_00250-000 ETC)
clear all
close all
clc
cd('C:\Documents and Settings\dgraham\Desktop\G-SUSX U65 text')
mkdir('results')
fid = fopen('MT_00063-000.txt');
datacell = textscan(fid, '%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f','HeaderLines',600);
fclose(fid);
cd('C:\Documents and Settings\dgraham\Desktop\G-SUSX U65 text\results')
%define variables based on datacell
Altitude = datacell{1,22}*3.2808399;
time = datacell{1,4};
temperature = datacell{1,5};
%%%%%START OF PLOTS %%%%%
figure('position', [0 0 800 1100], 'PaperPositionMode', 'auto');
blah blah blah subplots using variables from datacell.
saveas(gcf,'results1.tiff')
%%%%%END OF PLOTS %%%%%

Akzeptierte Antwort

Rick Rosson
Rick Rosson am 6 Apr. 2012
for k = 50:250
inputFileName = sprintf('MT_%05i-000.txt',k);
outputFileName = sprintf('results%05i.tiff',k);
...
fid = fopen(inputFileName);
...
fclose(fid);
...
saveas(gcf,outputFileName);
...
end

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 6 Apr. 2012

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by