필터 지우기
필터 지우기

Slow 3D video rendering & underutilized system usage

조회 수: 9 (최근 30일)
Aser
Aser 2024년 1월 3일
댓글: Aser 2024년 1월 4일
I'm new to matlab and trying to create a basic 3D plot movie in matlab only to find my system severly underutelized and the plotting code running extremely slow. Everything is preallocated and precaluclated and it's only the loop where the frames are captured that is very slow. It captures 1200 frames at 80 fps so it's a 15 second animtion. This takes around 6 minutes to complete where when i checked my CPU & GPU usage on task manger they dont go over ~20% and ram usage also peaks around ~60%. I'm looking for some advice on what would be done here to improve this even slightly.
I also tried to have
set(f, 'Visible', 'on');
set to off only for no changes to occur & parfor seems to just go slower.
Thanks!
The code:
%E_t is a 200*200*1200 double
f = figure;
set(f, 'Visible', 'on');
set(f, 'Renderer', 'opengl');
figureWidth = 1800; % Adjust as needed
figureHeight = 900; % Adjust as needed
set(gcf, 'Position', [50, 50, figureWidth, figureHeight]);
myFrames = cell(numSamplesTime,1);
myFrames(:) = {zeros(figureHeight, figureWidth, 3, 'uint8')};
colorMap = cell(numSamplesTime,1);
colorMap(:) = {zeros(256, 3)};
% Now combine these to make the array of structures.
myMovie = struct('cdata', myFrames, 'colormap', colorMap);
tic
maxValue = max(E_t(:));
for tIndex= 1 : numSamplesTime - 1
subplot(1,2,1);
imagesc(x,y,E_t(:,:,tIndex)'); colorbar; clim([0, maxValue]); colormap("jet");
title("|E(x,y,t)| Heatmap")
xlabel('X');
ylabel('Y');
axis square;
subplot(1,2,2);
mesh(x,y,E_t(:,:,tIndex)'); colorbar; clim([0, maxValue]); colormap("jet");
title("|E(x,y,t)| 3D-plot")
xlabel('X');
ylabel('Y');
zlabel('|E(t)|');
axis([0 a 0 a 0 maxValue]);
axis vis3d;
thisFrame = getframe(f);
myMovie(tIndex) = thisFrame;
end
close(f);
toc
%output: Elapsed time is 435.840855 seconds.
A frame of the animation:
Task manger with simualtion running:
Profiling results (which i dont understand but am sure will help somehow?)

채택된 답변

Walter Roberson
Walter Roberson 2024년 1월 3일
Instead of setting everything up every iteration, set up once before-hand and update objects inside iterations.
tIndex = 1;
subplot(1,2,1);
img121 = imagesc(x,y,E_t(:,:,tIndex)');
colorbar;
clim([0, maxValue]);
colormap("jet");
title("|E(x,y,t)| Heatmap")
xlabel('X');
ylabel('Y');
axis square;
subplot(1,2,2);
mesh122 = mesh(x,y,E_t(:,:,tIndex)');
colorbar;
clim([0, maxValue]);
colormap("jet");
title("|E(x,y,t)| 3D-plot")
xlabel('X');
ylabel('Y');
zlabel('|E(t)|');
axis([0 a 0 a 0 maxValue]);
axis vis3d;
for tIndex= 1 : numSamplesTime - 1
thisdata = E_t(:,:,tIndex)';
img121.CData = thisdata;
mesh122.CData = thisdata;
pause(0.1)
thisFrame = getframe(f);
myMovie(tIndex) = thisFrame;
end
  댓글 수: 1
Aser
Aser 2024년 1월 4일
That worked, thank you! A 2000% improvement from a small OOP-like change which i never known was even possible.
A small note however in case anyone comes across this post; you forgot to update zData so the for loop should include this line as well:
mesh122.ZData = thisdata;
& Thanks again for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by