# MATLAB: How to run a code for several files also how to stop the code for a specific number of files and give output

I have following code:
• PATH = 'C:\myFilesAreHere\';  %remember the last \files=dir([PATH,'*.dat']) ; %get info about all files in PATH that ends with .datfileNames={files.name};     %extract only filenames, put them in a cell.%im not sure if the filenames are allredy sorted or not but to be sure:fileNames=sort(fileNames);nFiles=numel(fileNames);    %count number of filescolorMap={'red','blue','green',... etc}  % if your run out of colors use e.g '-.red'for i=1:min(nFiles,10)      %run for either 1:10 or 1:nFiles if nFiles<10.        A=load([PATH,'fileNames{i}']);        % your code        figure;plot(X,Y,colorMap{i} );  end