/ concept-collection / numbl-embed-example
Sign in
concept-collection / numbl-embed-example
numbl-embed-example / README.md
63 lines · 1.9 KBPreviewCodeBlameHistoryRaw
1> **Early Stage & Experimental** - This project is in early development and should be considered experimental.
3# numbl Embed Example
5This repository demonstrates how to embed interactive MATLAB scripts in Markdown files using [numbl-embed](https://github.com/flatironinstitute/numbl). When rendered on GitHub Pages, the embedded scripts become editable and executable directly in the browser via [numbl](https://numbl.org).
7## Example
9* **Rendered**: [example1](https://concept-collection.github.io/numbl-embed-example/example1)
10* **Source**: [example1.md](https://raw.githubusercontent.com/concept-collection/numbl-embed-example/refs/heads/main/example1.md)
12```markdown
13<script src="https://numbl.org/numbl-embed.js"></script>
15This demonstrates how to embed numbl in a markdown file that can be rendered on GitHub pages.
17<numbl-embed>
18<iframe width="100%" height="600" frameborder="0"></iframe>
19<script type="text/plain" class="matlab-script">
20% Matrix operations example
21A = [8, 1, 6; 3, 5, 7; 4, 9, 2];
22disp('Matrix A:')
23disp(A)
25disp('Sum of each row:')
26disp(sum(A, 2))
28disp('Sum of each column:')
29disp(sum(A, 1))
30</script>
31</numbl-embed>
32```
34It even works with plotting:
36```markdown
37<script src="https://numbl.org/numbl-embed.js"></script>
39This demonstrates how to embed numbl in a markdown file that can be rendered on GitHub pages.
41<numbl-embed>
42<iframe width="100%" height="600" frameborder="0"></iframe>
43<script type="text/plain" class="matlab-script">
44% Damped oscillation
45t = linspace(0, 10, 200);
46y = exp(-0.3 * t) .* sin(2 * pi * t);
47plot(t, y)
48title('Damped Oscillation')
49xlabel('Time')
50ylabel('Amplitude')
51</script>
52</numbl-embed>
53```
55You can also embed an interactive REPL with `mode="repl"`:
57```markdown
58<script src="https://numbl.org/numbl-embed.js"></script>
60<numbl-embed mode="repl">
61<iframe width="100%" height="500" frameborder="0"></iframe>
62</numbl-embed>
63```
moveopenescclose