janklab / MlxShake

Export Matlab Live Scripts to Markdown, HTML, PDF, and more.
Other
9 stars 1 forks source link

Animated for-loop plots as embedded videos #1

Open FannoFlow opened 3 years ago

FannoFlow commented 3 years ago

when plotting code is drawn in a loop, matlab live scripts will covert them to a video playback.

This would be really cool to see exported in markdown. perhaps as a gif?

a = axes;
axis(a, [0,2*pi,-1,1])
hold(a, "on")

for i = linspace(0, 2*pi)
    scatter(a, i, cos(i), 'b')
    drawnow limitrate
end

image

apjanke commented 3 years ago

Great idea! Let's do this.

They could be embedded as animated GIFs, or maybe as real video formats.

First thing to do is figure out what format Matlab's "Export Live Script to LaTeX" dumps them out as. And have a look at what its "Export to HTML" does with them, too; that may support different media formats.

apjanke commented 3 years ago

Okay, I added a TODO and an example .mlx for this: https://github.com/janklab/ExportMlx/commit/94fe644b07b5d6d8604cbc62c23147f158a0ad00.

Hmmm. This might be nontrivial: I think what you're actually seeing when you Run the Live Script is just Matlab progressively updating the preview image upon passes through the loop, and once execution of that code block is finished, what's left is just a static image, not a video of any sorts.

When exporting the mlx to latex with Matlab (R2019b), you get just a static .png file, and when exporting to HTML, you end up with a PNG embedded inside the HTML file using a <img src="data:image/png;base64,..."> tag.