Export animated plot to html

16 次查看(过去 30 天)
Jonas van Nijnatten
回答: Moin 2022-7-11
Is it possible to export an animated plot in the Live Editor to .html format?
The figure is animated within the Live editor. It exports to html without error, but the figure is static when I view it in the html file.
I checked using the following browsers: Firefox, MS Edge, chrome.
Here is some example code:
% Allow Figure Animation
settingsObj = settings;
settingsObj.matlab.editor.AllowFigureAnimation.TemporaryValue = 1;
% generate random data
data = rand(1,20);
% prepare fig
figure;
p = plot(NaN);
xlim([0 20]);
ylim([0 1])
% start animation
for i = 1:20
p.YData = data(1:i) ;
pause(.2)
end

回答(1 个)

Moin
Moin 2022-7-11
I understand, you are trying to export an animated plot to html. It is exporting the script to HTML but the figure is still static. There is no direct option for doing this, but there is way to make this happen.
Steps:
  1. You can save the plot animation to a video file, while it is plotting frame by frame.( Refer this for the same: https://in.mathworks.com/matlabcentral/answers/455886-how-to-save-animated-plots#answer_370280 )
  2. Now export your script to HTML. Open it in any file editor and delete the image tag of the plot.
  3. Now add the below code in the HTML file to add video element.
<video width="320" height="240" controls>
<source src="fileName.mp4" type="video/mp4">
</video>
Now open the HTML file in your browser. You can find that the plot animation video is playing.
Alternatively, you can convert this video to gif and add that to your HTML file as well.

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by