Export animated plot to html

22 Ansichten (letzte 30 Tage)
Jonas van Nijnatten
Jonas van Nijnatten am 30 Apr. 2021
Beantwortet: Moin am 11 Jul. 2022
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

Antworten (1)

Moin
Moin am 11 Jul. 2022
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.

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by