Live scripts enable you to combine your analysis and an explanation of that analysis into a single document. You have already seen and interacted with live scripts throughout this course. For example, you explored tornado events from 2013 using a script similar to this one. Now, you'll learn how to create a live script of your own. Live scripts are built by combining text and code elements as needed to create your final document. Formatted text, images, equations, and hyperlinks are added in textbox. While executable code and comments, are added in code blocks. You can distinguish the two by their background color. Code blocks have a gray background, like what you see here, and text blocks have a white background. To get started, you first need to create a new live script. On the Home tab click "New Live script" to open a blank live script in the live editor. Did you notice that your active tab has changed? Three new tabs have appeared and a live editor tab is now active. As you learned previously, many of the capabilities of MATLAB are discoverable via the toolstrip. You can hover over the icons to discover what each one does. Before you start creating your live script, be sure to set your current folder. You will be using the 2013 storm events data along with the data import function you created previously. So make the folder containing those files the current folder. Now the data can be loaded. Once the code has been added to your live script click "Run". Because we left the semicolon off, a preview of the variable will appear in the output pane on the right. We don't really have a specific question to answer yet. So let's explore the dataset for something interesting to look into. A heatmap is a great way to visualize potential relationships between two variables. Let's look at a breakdown of event types by month. Click Run to execute the code and see the outputs. By default, the results appear in a separate pane to the right. But you can change this to be inline if you want. To change it, click the View tab, and then output inline. The output location can be changed at any time and applies to all output in the document. Try it out to decide which view you prefer. You can also start adding your thoughts and findings as you analyze the data. That way, anyone with a live script can understand what you did. Text blocks can be added anywhere by placing the cursor and clicking text. You can change the formatting of the text to create titles, and headings, and to add a list. Let's also center the title. You can also split the code into sections and then run the code in a single section. This is especially useful as you develop and test your code. Here, the first few lines load and prepare the data for analysis. Loading the data takes time but only needs to be done once. You can iterate on the analysis code more efficiently by placing a section break after the line of code that places the months in order. To do this, position the cursor and click section break in the toolstrip. Test this out by clearing the output and then running the code section by section. Click the View tab and select Clear all output. Then place the cursor in the first section and click Run Section. Notice that the blue bar on the left turns solid wants to code has run. Now place the cursor in the second section. Note that the bar on the left is striped to indicate the code in this section has not yet been run. Click Run Section to display the heatmap again. There is a lot of data in this heat map, which can make it hard to see and interpret. You can make it bigger by adjusting the width of the output display panel. If it's still difficult to see, you can open the heatmap in a new figure window. Hover over the heatmap and when the axes toolbar appears, click open in figure window. That's interesting, there are lots of hail events during the summer months. There are also numerous thunderstorm wind events during the same months. Perhaps the two events are related. Both of these events have latitude and longitude values, so you can create a geo density plot to see if the events are concentrated in the same locations. Add the code for displaying Hail, and click Run Section. These events appear to be concentrated mostly in the central United States. Now include code for thunderstorm wind and rerun the section. No obvious relationship is apparent on the map, since these events appear to be concentrated mostly in the Eastern United States. This is a good place to update the live script with a summary of your findings. You could add a note about why you looked at these events and what you observed. A good next step might be to look at the data for specific state. Let's create a new section for this. You can reuse the same code as before, and add a second condition to the logical indexing to select events that occurred in a single state. For example, Texas. Once the changes are made, click Run Section. This plot shows a few areas that are worth looking into further. For example, this cluster around Amarillo. But how do you select just these events? One way could be to look at storms within a certain distance of Amarillo. You can use the haversine formula to calculate this distance using the latitude and longitude values contained in the data set. Many people may be unfamiliar with this formula. You can add the equation to the live script and include a hyperlink to a reference page. Equations are added to text blocks from the Insert tab. First place the cursor, then expand the menu below the equation icon and select equation. A new tab will open with options that help you interactively build your equation using predefined symbols, and structures. For example, this structure lets you add the sine squared term. You can also combine structures like parentheses around a fraction by adding one structure inside another. This symbol will add the dot to indicate multiplication. When you're done, click outside the equation editor to exit. To add a hyperlink, highlight the text, click hyperlink on the Insert tab, and paste the URL. You can add the calculated distance as a new variable in a table, and use a conditional expression to select the desired events. Here, you are checking for events within eight kilometers or about five miles of Amarillo Texas. Once the data is selected, you can visualize it however you want. Because you are interested in the timing of events in relation to each other, you could consider displaying a table or perhaps a heatmap. Here you see that on May 28th there were multiple hail and thunderstorm wind events. The wind events were recorded first over one hour span. Multiple hail events were recorded over a 40-minute span starting approximately five hours later. You could check other cities and states, but at this point you can summarize your findings. After finalizing the text and organizing the live script as desired, you are ready to share it with others. Be sure to save your final version. Note that if you expand the Save Menu, you have the option of exporting your lives script to a variety of common file formats. For example, selecting PDF would create a new document containing the text, code, and outputs in a format that anyone can view. In summary, live scripts let you combine runnable code with formatted text. You can add formatting to create a report to share with others. The ability to export to a variety of formats enables you to distribute your analysis to people that do not have access to MATLAB. Now you are ready to learn how to make your scripts interactive with controls.