every for loop never stops running
5 views (last 30 days)
While trying to write a code for SVM classification, I noticed that once I get to the for loop to loop through subfolders to obtain files sequentially, the loop nevers tops running until I shut down my matlab. I have tried running other for loops from old codes that used to run and the same thing: e.g
for s = 1:length(nsubs).
I've uninstalled my MATLAB version 2020b and installed version 2022a. still, the same thing. I have tried clearing my RAM and installed an antivirus for fast performance, still, the for loops won't stop running. Every other preceeding lines of code runs until it gets to the for loop, then it never stops running. What can I do ?
I am using a windows 10 laptop.
Jan on 27 Jul 2022
Neither uninstalling Matlab nor a virus scanner can be the solution. Don't try wild things, because "gunshot-programming" is not useful.
Use the debugger instead. Set a breakpoint in the line with the for command and step through the code line by line. Then you will find out, which of the commands take a long time. This will explain, why the loops runs longer than you expect. "Never stops" is most likely not the case, but it is just slow.
The profiler helps also to identify the runtime of the single lines. Start it by
Change the loop to:
for s = 1:2 % length(nsubs)
Run the code and wait. Afterwards:
shows you, where the time is spent.
Posting the code would help also. Maybe the RAM is exhausted and Matlab starts to use virtual RAM, which is stored on the slow hard disk. This slows down the processing by a factor of 100 or 1000.