in this video i'm going to review the
main features of livescript
click a new livescript button or use a
new menu to open a new live script
you can also type edit and define name
with mlx extension
in a live script you can mix up a text
and code together
enter code in the grade areas and click
on the text button
to enter some text describing what you
are going to do
text is like a comment but without
percentage
then click on the code button to enter
more code
note that after typing few letters of
the function name
it will pop up a list of the available
functions starting with that prefix and
when you type the open parenthesis
live editor will automatically complete
it with the closed one
so we can collect now a bunch of
commands
to create a whole code section which is
the
kind of computational unit and then
click on run section button to
immediately get the output
this is a really useful workflow you
add more text to provide a more
background and explanation of the work
in progress
and then you add a new lines of code
maybe to get a plot
as you can see matlab will always assist
you suggesting the correct
syntax for any optional different
parameter
to re-execute the whole code click on
the run section button again to see the
graphics as well
livescript is great to quickly
experiment what happens when you change
a parameter
or what happens if we change the sign
in the function definition or what
happens if we add a square
if we stumble in any syntax issue don't
worry
the error message can help to understand
what is missing and correct
we could also add a breakpoint to debug
the code
and execute a step by step to catch also
semantic
arrows you can step to next line or
continue to next breakpoint
and when you are okay with the code you
can stop debugging
and eliminate all the breakpoints
but just a note when you save a script
only mlx format allows to store output
and text inside the file itself
a traditional script would lose all the
output and would turn text into comments
anyway any script can be converted into
livescript simply by resaving it as
mlx now let me jump into a larger live
script
to review how to format the text in
different ways
for example to create a title you click
on the text and simply choose title in
the style menu
or to create a heading you can either
use the style menu
a shortcut or put a markdown before the
text
the double shot
to add a section break you can use
either a section break button
or the shortcut ctrl alt enter
if you put a double percentage before a
text you turn this into a heading
with a new section break simultaneously
of course you can also create different
levels of headings
using the style menu again
all these headings will be used
conveniently to create a table of
contents
in fact if we just scroll up to the
beginning
we can go to the insert tab and click on
the table of contents button
every item here in the table now is a
hyperlink to the corresponding section
now suppose we want to tell a relevant
story let's say about a noisy signal
we'd better highlight the story with a
new heading
and check that any new heading is
automatically added
to the table of contents but to create a
good story we need additional resources
for example we could insert a hyperlink
pretty mediate to copy the link and this
way
you have a direct link from the script
to a web page
maybe describing more statistics for
random models
what about adding a mathematical
equations
click equation to access the equation
editor
it provides many symbols like greek
letters errors
operators radicals derivative integrals
that can help write an equation you can
also use a ctrl
alt e shortcut to edit an equation
and if you are familiar with latter
comment you can directly type latex
comment
they all typically start with a
backslash
so backslash mu backslash sigma
will return the symbols for the mean and
the standard deviation
and finally to give also a visual idea
of noisy signal
we can insert an image let's choose
our favorite jpeg
and here we are we can resize it as we
like
and now we are ready to switch from text
to code
to implement our story with the nice
executable commands
we can start copying some code from the
previous example
maybe taking a smaller step here
and we can click on the run section to
execute and show the output
on the top right bar we can click to
visualize output e line
after each command if we like or we can
keep the default visualization of the
output on the right
let's go on with a custom plot
when you start writing the plot comment
livescript will help with additional
parameters
for example we can set the line width
properties to two you can run the
section and see the thicker plot
of course we can experiment any code
change
we can try to change the color to red
and run again when you click on the plot
you can quickly add a grid a title or
other annotations
interactively and also you can
automatically
upgrade the code with the corresponding
commands
now let's make a copy of this code
because i'd like to show you an
interesting feature to
reuse it but first
let me make it a bit more flexible
with a couple of extra parameters maybe
one for the title
one for the color
okay let's see if it works
now select the code and then click on
refactor
to convert the code automatically into
a local function you just need to rename
it
note that any local function must be put
at the end of the script
and closed by an end
the live scripter will substitute the
function call
automatically and we can try to make a
change and reuse the local function
so refactoring is very useful to
modularize the code
and make it more readable
to interact a bit more with our code we
can include
some ui control for example let's start
with a parameter alpha
that will control the level of noise we
want to introduce
and redefine the signal by adding random
numbers
with a normal distribution controlled by
alpha
reusing the local function created
before is a certainly a good idea
to visualize and understand the effect
of adding this noise to the signal
but how can we explore different values
of alpha
the easiest way go to insert tab click
controls
and choose one of the available controls
for example a numeric slider
we can set the feasible range of values
the minimum
the maximum and the incremental step
and here's the magic anytime we move the
slider
all the comments in that section will
re-execute so it will regenerate the
random noise and update the plot
so live controls can really help
understand how a parameter
impact on the model and gain a deeper
insight
livescript can also speed up some common
tasks in data analysis
and pre-processing click tasks button
choose one of the multiple tasks for
example smooth
data and an interactive interface
will show up where you can select the
input data
choose a smoothing method or change the
smoothing factor
and immediately see the output you can
experiment with another method
adjust the smoothing factor
or try another method again until you
get a good performance
after this interaction you can see the
automatically generated code
and clicking on the three dots you have
three options to see in the script
the control only the code only
or both control and code together
as a conclusion we are now ready to
export the whole live script into a
shareable document
you can go to the top right bar and
choose to hide a code if you want
if you hide a code the document will
contain only text and output
but i'm not going to do this now just in
case
we can choose to hide the code or not
also from the view tab
now go to save button and choose
export to pdf or another format
available
word html latex and after a few seconds
you can see the pdf completed with the
table of contents
all the formatted text and the output
and that's it
so for your reference there is a nice
cheat sheet downloadable from our
mattress website i hope this video was
useful
and happy livescript