MATLAB: Plotting with for loop for many text files

direxportfor loopMATLABplottingtextscan

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 %%%%%

Best Answer

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