フィルターのクリア

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 Center および File Exchange2-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