Clear Filters
Clear Filters

Out of memory error

32 views (last 30 days)
Luccas S.
Luccas S. on 18 Jul 2024 at 15:32
Commented: Walter Roberson on 18 Jul 2024 at 17:47
I'm trying to run the code below, it works well and does its job. The problem is that it is not capable of running all iterations continuously, the out of memory error always appears and I end up having to restart it or start it running from where it left off. I've already made some changes, but the error still persists. Does anyone have any suggestions or ideas on how I can get around it?
The algorithm saves one image from each cycle, with each iteration almost 1800 images are generated, I don't know if this is what is causing the error to occur. But using the close(figh) command it closes the image that is used to save...
clear all; close all; clc; warning off;
baseDir = 'C:\Users\Lucas\Documents\Mestrado\wsst';
caso = 2; % Selecionando o caso 2 para simulação
N = 32;
ciclo = 128;
tipos_de_falta = ["A", "B", "C", "AB", "BC", "CA", "ABC"];
hs = [0, 25, 50, 75, 100];
runs = 1:9;
for idx_tipo = 1:length(tipos_de_falta)
for idx_h = 1:length(hs)
for idx_run = 1:length(runs)
clearvars -except baseDir caso N ciclo hs tipos_de_falta runs idx_tipo idx_h idx_run
tipo_falta = tipos_de_falta(idx_tipo);
h = hs(idx_h);
run = runs(idx_run);
if caso == 2
[Ip_faseA, Ip_faseB, Ip_faseC, Is_faseA, Is_faseB, Is_faseC, If_faseA, If_faseB, If_faseC, t, instanteChaveamento, prefixo_arquivo, tipo_falta_descricao] = PSCAD_2(h, N, tipo_falta, run);
else
disp('Opção inválida. Por favor, escolha 1, 2 ou 3.');
break;
end
pastaCaso = ['Falta_', prefixo_arquivo, '_em_', num2str(h),'_da_LT'];
casoPath = fullfile(baseDir, pastaCaso);
if ~exist(casoPath, 'dir')
mkdir(casoPath);
end
chaveamentoFolderName = sprintf('Chaveamento_%0.6f_s', instanteChaveamento);
chaveamentoFolderName = regexprep(chaveamentoFolderName, '[\s\.]', '');
chaveamentoPath = fullfile(casoPath, chaveamentoFolderName);
if ~exist(chaveamentoPath, 'dir')
mkdir(chaveamentoPath);
end
subFolders = {'pre_falta', 'chaveamento', 'falta'};
phases = {'Fase A', 'Fase B', 'Fase C'};
for i = 1:length(subFolders)
subFolderPath = fullfile(chaveamentoPath, subFolders{i});
if ~exist(subFolderPath, 'dir')
mkdir(subFolderPath);
end
for j = 1:length(phases)
phaseFolderPath = fullfile(subFolderPath, phases{j});
if ~exist(phaseFolderPath, 'dir')
mkdir(phaseFolderPath);
end
end
end
Ida = If_faseA;
Idb = If_faseB;
Idc = If_faseC;
Ida = normalize(Ida);
Idb = normalize(Idb);
Idc = normalize(Idc);
total_a = length(t);
total_d = t(end) - t(1);
fs = total_a / total_d;
for i = 1:(total_a - ciclo + 1)
i_limite = min(i + ciclo, total_a);
tmin = t(i);
tmax = t(i_limite);
if tmin >= 1
break;
end
if tmax < instanteChaveamento
pasta_destino = 'pre_falta';
elseif tmin >= instanteChaveamento
pasta_destino = 'falta';
else
pasta_destino = 'chaveamento';
end
for fase = ['a', 'b', 'c']
[sst, f] = wsst(eval(['Id' fase '(i:i_limite)']), fs, 'ExtendSignal', true);
figh = figure('Visible', 'off');
pcolor(t(i:i_limite), f, abs(sst));
shading interp;
set(figh, 'Position', get(0, 'Screensize'));
set(gca, 'Visible', 'off');
colorbar('off');
caminho_do_arquivo = sprintf('%s\\%s\\Fase %s\\TF_Ridges_Fase_%s_%s_em_%d_LT_%d.jpg', ...
chaveamentoPath, pasta_destino, upper(fase), upper(fase), prefixo_arquivo, h, i);
exportgraphics(gca, caminho_do_arquivo);
close(figh); % Fechar a figura atual para economizar memória
end
end
end
end
end
  1 Comment
Walter Roberson
Walter Roberson on 18 Jul 2024 at 17:47
I do not see any obvious reason.
I am a bit concerned about the use of eval()

Sign in to comment.

Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!