Animate results from PDE toolbox

Hi,
I am trying to animate results from a PDE toolbox script.
F=figure(1);
MyVideo = VideoWriter(sprintf('2DSys.avi'));
MyVideo.FrameRate = 10;
MyVideo.Quality = 100;
open(MyVideo);
for i = 1:length(result.SolutionTimes)
pdeplot(MyModel,'XYData',result.NodalSolution(:,i),'ColorBar','off');
title({['Time=' num2str(result.SolutionTimes(i)) 's']})
% colormap(jet)
% axis tight
% ax = gca;
% axis off
M(:,i) = getframe(F);
writeVideo(MyVideo, M(:,i));
drawnow
end
But I don't have any frames written to my file. The script is executing without errors on my pc.
On analyzing my M output structure I see that the colormap entries turn out empty. Attaching M as well.

 採用された回答

VBBV
VBBV 2022 年 11 月 22 日

0 投票

M(:,i) = getframe(gcf); % use gcf

7 件のコメント

Hashim
Hashim 2022 年 11 月 22 日
Thank you for your input but it's not working for me.
VBBV
VBBV 2022 年 11 月 22 日
編集済み: VBBV 2022 年 11 月 22 日
On analyzing my M output structure I see that the colormap entries turn out empty.
because you have commented colormap and disabled it in pdeplot
pdeplot(MyModel,'XYData',result.NodalSolution(:,i));
title({['Time=' num2str(result.SolutionTimes(i)) 's']})
colormap(jet)
VBBV
VBBV 2022 年 11 月 22 日
編集済み: VBBV 2022 年 11 月 22 日
close(MyVideo) % add this line too after end of for loop
you also need to close video after writing data, it doesnt appear in your code. otherwise , Videowriter still expects more data to be written to complete the video
Hashim
Hashim 2022 年 11 月 22 日
No, I am afraid it's still not running. Have you been able to make it work?
VBBV
VBBV 2022 年 11 月 22 日
What is "stll not running" ? can you attach relevant files ? e.g. MyModel
Hashim
Hashim 2022 年 11 月 22 日
編集済み: Hashim 2022 年 11 月 22 日
The script that I attached is not running. I have already attached the result variable that has the values I want to animate. The rest of the script seems to be working fine.
Hashim
Hashim 2022 年 12 月 6 日
編集済み: Hashim 2022 年 12 月 6 日
This kinda works
figure;
maxc = max(max(result.NodalSolution));
minc = min(min(result.NodalSolution));
MyVideo = VideoWriter(sprintf('2DSys.avi'));
MyVideo.FrameRate = 10;
MyVideo.Quality = 100;
open(MyVideo);
for i = 1:10
pdeplot(MyModel,'XYData',result.NodalSolution,'ColorBar','off','Mesh','off');
title({['Time=' num2str(i) 's']})
caxis([minc maxc]);
colormap(jet)
axis tight
ax = gca;
ax.DataAspectRatio = [1 1 1];
M(i) = getframe(gcf);
writeVideo(MyVideo, M);
end
close(MyVideo)

サインインしてコメントする。

その他の回答 (0 件)

製品

リリース

R2021b

質問済み:

2022 年 11 月 21 日

編集済み:

2022 年 12 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by