Script Skips a portion of code
6 views (last 30 days)
Show older comments
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
MonthBox=['C:/Folder_A/'];
Monthly=dir(MonthBox);
%Open file every month
DayCount=0;
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.
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!