why do my subplot axes fill out figure after loops ends?
1 回表示 (過去 30 日間)
古いコメントを表示
while loop is running plots appear kind of small in upper left corner of figure window.. after loop end suplot´s fill out figure window properly (as pleased)
any help is much appreciated
KR, M.
switch n
case 1
%% Explicit Euler Scheme
t = 0;
un = u0;
tStart = tic;
for i = 1:Nt
fn = f(x(:),y(:),t);
% stability check
stability = dt*kappa(t)*(1/(dx^2) + 1/(dy^2));
if stability >= .5
fprintf('Scheme is not stable!!')
break
end
% 2D Laplace operator
Ln = dt*kappa(t)*L;
% applying BC
% NEUMANN all over
% NEUMANN = 0.5;
% [Ln,fn] = NeumannBC(Ln,fn,NEUMANN,in, dx, 1);
% [Ln,fn] = NeumannBC(Ln,fn,NEUMANN,is,-dx,-1);
% [Ln,fn] = NeumannBC(Ln,fn,NEUMANN,ie, dy, Ng);
% [Ln,fn] = NeumannBC(Ln,fn,NEUMANN,iw,-dy,-Ng);
% DIRICHLET all over
[Ln,un,fn] = DirichletBC(Ln,un,fn,zeros(size(in)),in);
[Ln,un,fn] = DirichletBC(Ln,un,fn,zeros(size(is)),is);
% [Ln,un,fn] = DirichletBC(Ln,un,fn,zeros(size(ie)),ie);
% [Ln,un,fn] = DirichletBC(Ln,un,fn,zeros(size(iw)),iw);
DIR_e = @(y) y.*(y-1);
DIR_w = @(y) sin(10*y);
[L,un,fn] = DirichletBC(L,un,fn,DIR_e(y(ie)),ie);
[L,un,fn] = DirichletBC(L,un,fn,DIR_w(y(iw)),iw);
% solving
S_exp = I + Ln;
unp1 = S_exp*un + dt*fn;
unp1 = reshape(unp1,[Ng Ng]);
fn = reshape(fn,[Ng Ng]);
% plotting
figure(1)
subplot(2,2,1)
surf(x,y,fn)
title('$source~term$')
subplot(2,2,2)
surf(x,y,unp1)
title('$numerical~solution$')
subplot(2,2,3)
contourf(x,y,fn)
title('$source~term$')
subplot(2,2,4)
contourf(x,y,unp1)
title('$numerical~solution$')
% reinitializing
unp1 = unp1(:);
fn = fn(:);
un = unp1;
% timestep
t = t+dt;
end
tEnd = toc(tStart);
fprintf(['Explizit Euler Scheme took ',num2str(tEnd),'s '])
break
0 件のコメント
回答 (1 件)
Ayush
2024 年 5 月 3 日
Hey lederaturm,
I understand that you are facing issue while plotting in loop in MATLAB.
The issue you're encountering is likely due to MATLAB's figure handling and rendering during the loop execution. This can happen due to the way MATLAB updates its graphics rendering engine during loop operations, especially for intensive computations or rapid updates to figures.
You can try inserting "drawnow" or a short "pause" command after your plotting commands as this can force MATLAB to update the figure window immediately, rather than delaying the update until after the loop finishes. This can help ensure that the plots are rendered correctly during each iteration.
% After your subplot commands
drawnow; % or pause(0.01);
Hope this helps!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!