Preallocate varible before run (the pc runs out of memory )
1 view (last 30 days)
Show older comments
Hello everyone I hope you can help me.
This code evaluates two variables: and . The length of each variable is 300.
When I run the code my PC runs out of memory and hangs. Can I optimize the code or free up memory while it runs?
phiH = (0:0.0033:1);% axis x
muZ = (0:0.0033:1);% axis y
%phiH = linspace(1.e-14,1,300);%eje x
%muZ = linspace(1.e-14,1,300);%eje y
LphiH = length(phiH);
LmuZ = length(muZ);
%
dotarray=cell(LphiH, LmuZ, 1);
parfor i= 1:LphiH
for j = 1:LmuZ
[H, ZH_H] = func_phiH_muZ(phiH(i),muZ(j));
if H(end-10:end)>2
if ZH_H(end-10:end)>10
dot=45; %suvirval
else
dot=20; %e out zoospore
end
else
dot=1; % total extinc
end
dotarray(j,i)={dot};
end
end
dotmatrix=cell2mat(dotarray(1:length(phiH), 1:length(muZ)));
%job1 = batch('val_phiH_phiH_22jul2021','CaptureDiary', true, 'Pool',4);
%load(job1)
%colormap(hsv);
image(dotmatrix, 'XData', phiH, 'YData', muZ);
I thank you for the help.
9 Comments
Image Analyst
on 14 Jan 2022
Maybe you don't need all that resolution. I'm not sure why a 300x300 array ends up using a bazillion terabytes but maybe you can get essentially the same answer with less. What happens if you use, like 20 points? Can you try this:
numPoints = 20;
phiH = linspace(0, 1, numPoints); % axis x
muZ = linspace(0, 1, numPoints); % axis y
Does that finish? How long does it take?
Answers (0)
See Also
Categories
Find more on MATLAB Mobile Fundamentals 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!