90 year data simulation in need of performance increase I developed some code for my masters project that will simulate 90 years daily data using 1000 different data sets. The code is working fine and gives the correct output that I wanted but the processing time are very high. It took about 8 hours to finish the simulation.

    tic
%% importing the csv file with selected column
files=dir('*_scen_*.csv');
for i=1:length(files);
    LHR=importcsv(files(i).name);

%% Definable variables
% Define These Value
TAW=-216;     %total available water
RAW=-129;     %readily available water
KC=1.0;       %crop coefficient
IRL=15;       %intense rain level
RC=(80/100);  %percentage of recharge 
RO=(1-RC);    %percentage of runoff

% The very first row of Soil Moisture Deficit
for j=1
    SMD(j,i)=(LHR.RAIN(j)-LHR.PET(j));
 if     SMD(j,i)&gt;0;
        SMD(j,i)=0;
 elseif SMD(j,i)&lt;RAW;
        SMD(j,i)=(LHR.RAIN(j)-(LHR.PET(j)*((TAW-SMD(j-1))/(TAW-RAW))));
 end
end

%for the following SMD Calculation
for k=2:(length(LHR.RAIN));
    SMD(k,i)=SMD(k-1,i)+(LHR.RAIN(k)-LHR.PET(k));
    % The SMD conditions
    if SMD(k,i)&gt;0;
       SMD(k,i)=0;
 elseif SMD(k,i)&lt;RAW;
     SMD(k,i)=SMD(k-1,i)+(LHR.RAIN(k)-(LHR.PET(k)*((TAW-SMD(k-1,i))/(TAW-RAW))));
    end
end
%Convert negative SMD to Positive
SMD=abs(SMD);

 %%Evapotranspiration Calculation
 for l=1:(length(SMD));
    if SMD(l,i)&lt;abs(RAW);
        AET(l,i)=LHR.PET(l);
    elseif SMD(l,i)&gt;abs(RAW);
        AET(l,i)=KC*LHR.PET(l)*((abs(TAW)-(SMD(l,i)))/(abs(TAW)-abs(RAW)));
    end
end
for m=2:(length(SMD));
    if SMD(m,i)&lt;abs(RAW);
        AET(m,i)=LHR.PET(m);
    elseif SMD(m,i)&gt;abs(RAW);
       AET(m,i)=KC*LHR.PET(m)*((abs(TAW)-(SMD(m-1,i)))/(abs(TAW)-abs(RAW)));
    end
end
%% HER calculation
for n=1:length(SMD);
    if SMD(n,i)&lt;(LHR.RAIN(n)-AET(n,i));
        HER(n,i)=(LHR.RAIN(n)-AET(n,i)-SMD(n,i));
    elseif SMD(n,i)&gt;(LHR.RAIN(n)-AET(n,i));
        HER(n,i)=0;
    end
end
%% Calculation of recharge anf runoff
for o=1:(length(HER));
    if (HER(o,i)+(abs(TAW)-SMD(o,i)))&lt;abs(TAW);
        RUNOFF(o,i)=0;
    elseif (HER(o,i)+(abs(TAW)-SMD(o,i)))&gt;abs(TAW);
        if HER(o,i)&gt;IRL;
            RUNOFF(o,i)=RO*HER(o,i);
        elseif HER(o,i)&lt;IRL;
            RUNOFF(o,i)=0;    
        end
    end
    if (HER(o,i)+(abs(TAW)-SMD(o,i)))&lt;abs(TAW);
        RECHARGE(o,i)=0;
    elseif (HER(o,i)+(abs(TAW)-SMD(o,i)))&gt;abs(TAW);
        if HER(o,i)&gt;IRL;
            RECHARGE(o,i)=RC*HER(o,i);
        elseif HER(o,i)&lt;IRL;
            RECHARGE(o,i)=HER(o,i);
        end
    end
end
%% rainfall
for p=1:length(LHR.RAIN);
RAINFALL(p,i)=LHR.RAIN(p);
PET(p,i)=LHR.PET(p);
end

end
clear i
clear j
clear k
clear l
clear m
clear n
clear o
clear p

toc


Is there any improvement scope for this code that might reduce the processing time? Sorry if the code looks unprofessional; I am in the beginner stage for MATLAB programming.
This cleanup code at the end is indicative of the problem with this program:


clear i
clear j
clear k
clear l
clear m
clear n
clear o
clear p



Nobody is going to reverse-engineer your minified / obfuscated code to understand it.  You will probably have a hard time understanding it yourself if you come back to it after a few weeks.  The program is therefore unmaintainable.

I wouldn't have much confidence in the correctness of the results, either.  The code should be broken down into functions, each of which has a single purpose, specific inputs and outputs, and is separately testable.