every for loop never stops running

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 comentarios

KSSV
KSSV el 27 de Jul. de 2022
Show us the code which is troubling you.
Also, please show us the output for
which length(nsubs)
Monalisa Chikezie
Monalisa Chikezie el 27 de Jul. de 2022
Editada: Monalisa Chikezie el 30 de Jul. de 2022
clc
clear all
%addpath = 'C:\Users\mo\Documents\MATLAB\spm12'; already on my path
GLM_dir='C:\Users\mo\Documents\MATLAB\GLM';
cd = GLM_dir;
%% Set the variables
% MRI scanner settings
TR=3.6;% Repetition time ( secs )
DT=0.225; %Micro time
TE = 0.05; % Echo time ( secs )
volumes=198;
% Experiment settings
nsubs= 60;
vois={'ldF', 'rdF', 'lvF', 'rvF'}; %VOI timing = {3.6 3.6 3.6 3.6 }
task_names={'Pictures', 'Words'};
%%
Subjects = 60;
start_dir = pwd;
for subject = 1:60
name = sprintf('sub-%02d',subject); %Navigates to each subfolder
% Load SPM
glm_dir = fullfile('..','GLM',name);
SPM = load(fullfile(glm_dir,'SPM.mat'));
SPM = SPM.SPM;
%Select relevant conditions to use as classes for SVM
Pictures = find(SPM.Sess.U(2).u(1:N*NT) > 0);
Words= find(SPM.Sess.U(3).u(1:N*NT) > 0);
% Load VOIs
f = {fullfile(glm_dir,'VOI_lvF_1.mat');
fullfile(glm_dir,'VOI_ldF_1.mat');
fullfile(glm_dir,'VOI_rvF_1.mat');
fullfile(glm_dir,'VOI_rdF_1.mat')};
lvF = f(1).name;
ldF = f(2).name;
rvF = f(3).name;
rdF = f(4).name;
end
% Move to output directory
cd(glm_dir);
% Return to script directory
cd(start_dir);
end
Illegal use of reserved keyword "end".
Monalisa Chikezie
Monalisa Chikezie el 27 de Jul. de 2022
Editada: Jan el 28 de Jul. de 2022
Basically, every for loop I try to run never stops running. including the simplest for loops. Sometimes, running for days if I allow it to. One ran for an entire weekend!
Walter Roberson
Walter Roberson el 27 de Jul. de 2022
SPM has a compatibility directory that duplicates some matlab functions, interfering with proper use of matlab. You need to delete that compatibility directory.
Monalisa Chikezie
Monalisa Chikezie el 27 de Jul. de 2022
hi, do you know which specific folders I should delete?
Walter Roberson
Walter Roberson el 28 de Jul. de 2022
spm12/external/fieldtrip/compat/matlablt2010b and I seem to recall that there is also a directory there for r2013
Jan
Jan el 28 de Jul. de 2022
Editada: Jan el 28 de Jul. de 2022
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?

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 27 de Jul. de 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
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 comentario

Monalisa Chikezie
Monalisa Chikezie el 30 de Jul. de 2022
Editada: Monalisa Chikezie el 30 de Jul. de 2022
Thanks for the response @Jan, I'm trying that out now. My RAM is 8GB but its usage is about 85-90%

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Etiquetas

Preguntada:

el 27 de Jul. de 2022

Editada:

el 30 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by