Script Skips a portion of code

6 views (last 30 days)
James on 6 Feb 2020
Edited: James on 31 Mar 2021
The code that I'm running is a bit lengthy and I'll post the part where I'm having the problem with. If more information is needed, I'll provide more lines of code.
%Open a data file in the same time zone
%Open file every month
for Monthlyi=4:length(Monthly)
% more code here
for Dailyi=4:length(Daily)
% more code here
Now, when I run the code, it skips the entire code after the "SumDayCounter=0;" . It does not enter the second "for" condition.
Can anyone think of a reason for this and a possible fix?
Apologies if the provided information is not enough. I can provide more, if needed.
Any advice is appreciated.
Thanks in advance.

Accepted Answer

Steven Lord
Steven Lord on 6 Feb 2020
If length(Daily) is less than 4, the result of the expression 4:length(Daily) will be empty and so the body of that loop will not be executed.
If you're looking to skip the files . and .., don't assume they are the first two files in the output of dir. Instead loop over the whole directory output and use continue to skip the body of the loop processing the file if the name matches one of those two special names.
James on 7 Feb 2020
This makes perfect sense. I could fix the error, thanks to both of you!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!