Code get stuck with nested loop and computer crashes after
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Victor Gimenez
am 19 Apr. 2022
Bearbeitet: Victor Gimenez
am 20 Apr. 2022
I am having an issue to run this block of code:
clear all
set(0,'DefaultFigureVisible','off');
a_data = cell(1,12560);
fft_a_data = cell(1,12560);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Code lines here before%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
count = 1;
for p2 = 1:a_trials
for p1 = 1:16
figHandle = figure;
topoplot(a_data(p1,:,p2),EEG.chanlocs,'style','map');
[X, Map] = frame2im(getframe(figHandle));
a_data{count} = X;
%FFT
Y = fft(a_data(p1,:,p2));
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
figHandle = figure;
topoplot(P1(fft_index),EEG.chanlocs,'style','map');
[X_fft, Map_fft] = frame2im(getframe(figHandle));
fft_a_data{count} = X_fft;
count = count + 1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Code lines here after%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(0,'DefaultFigureVisible','on');
At the beginning the computer looks like running it but after it stops and whole system crashes, how should I handle this issue? When I consider a range for p2=1:5 and p1=1:5 it is running normally but to this range p2=1:785 I can't able to perform it. The topoplot belongs to EEGLab toolbox.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 20 Apr. 2022
Why are you plotting those things anyway? Just to look at them? How about if you just opened a figure before the loops, and then looked at the pair of plots inside the inner loop? You're overwriting X, Map, X_fft, and Map_fft on each inner loop iteration anyway. Why? Were you planning on making a movie out of all of them?
clear all
% set(0,'DefaultFigureVisible','off');
a_trials = 2; % Whatever...
a_data = cell(1,12560);
fft_a_data = cell(1,12560);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Code lines here before%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
count = 1;
abort = false;
% Create new figure and maximize it.
figHandle = figure;
figHandle.WindowState = 'maximized';
for p2 = 1:a_trials
for p1 = 1:16
% Make first plot in upper half of the figure.
h1 = subplot(2, 1, 1);
cla;
topoplot(a_data(p1,:,p2),EEG.chanlocs,'style','map');
[X, Map] = frame2im(getframe(h1));
a_data{count} = X;
%FFT
Y = fft(a_data(p1,:,p2));
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% Make second plot in lower half of the figure.
h2 = subplot(2, 1, 1);
cla;
topoplot(P1(fft_index),EEG.chanlocs,'style','map');
[X_fft, Map_fft] = frame2im(getframe(h2));
fft_a_data{count} = X_fft;
count = count + 1;
promptMessage = sprintf('Look at your plots for p1=%d and p2=%d.\nDo you want to Continue processing,\nor Quit processing?', p1, p2);
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
abort = true;
break; % or break or continue.
end
end
if abort
break;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Code lines here after%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set(0,'DefaultFigureVisible','on');
1 Kommentar
Weitere Antworten (1)
Jan
am 19 Apr. 2022
What is a_trials?
It looks like you want to run 12560 iteration. You open two figures in each iteration, so there is a total of 25120 open figures. Although they are invisible, they need a lot of memory. The crash means, that the memory is exhausted.
Either close the figures, if you do not need them anymore. Or reuse the existing figures, which would be much moire efficient. See e.g. clf.
2 Kommentare
Siehe auch
Kategorien
Mehr zu DSP Algorithm Acceleration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!