필터 지우기
필터 지우기

every for loop never stops running

조회 수: 13 (최근 30일)
Monalisa Chikezie
Monalisa Chikezie 2022년 7월 27일
편집: Monalisa Chikezie 2022년 7월 30일
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.
  댓글 수: 8
Walter Roberson
Walter Roberson 2022년 7월 28일
spm12/external/fieldtrip/compat/matlablt2010b and I seem to recall that there is also a directory there for r2013
Jan
Jan 2022년 7월 28일
편집: Jan 2022년 7월 28일
Note:
pwd = GLM_dir;
It is a bad idea to shadow the function pwd by a variable. Maybe you mean:
cd(GLM_dir);
The posted code does not contain any user-defined functions of functions of external toolboxes. All you do is loading files. So set a breakpoint in the profiler and step through the code line by line. Findout, in which command the processing is stalled. Stop and restart Matlab. The next time set a breakpoint in the failing line and step into this command until you find the command, which is responsible for the problem. It might contain an infinite loop.
Where does Matlab stop if you press Ctrl-C during the code runs "forever"? Is this reproducibly the same command?
Do you use external toolboxes? If so, which one?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2022년 7월 27일
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
profile on
Change the loop to:
for s = 1:2 % length(nsubs)
Run the code and wait. Afterwards:
profile report
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.
  댓글 수: 1
Monalisa Chikezie
Monalisa Chikezie 2022년 7월 30일
편집: Monalisa Chikezie 2022년 7월 30일
Thanks for the response @Jan, I'm trying that out now. My RAM is 8GB but its usage is about 85-90%

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by