21 MATLAB Features You Need Now - MATLAB
Video Player is loading.
Current Time 0:00
Duration 21:36
Loaded: 0.76%
Stream Type LIVE
Remaining Time 21:36
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 21:36

    21 MATLAB Features You Need Now

    Overview

    Are you getting the most out of MATLAB®, or are you still using it just the way you were taught your first year in university? With over 2,000 people working year-round to design, build, test, and document MathWorks products, it is a safe bet that there are more than a few useful features you don’t know.

    This fast-paced talk will introduce at least 21 features you can start using today to make your use of MATLAB more efficient, more effective, and more fun. Some features will be very new, while others may be 5, 10, or maybe even more than 15 years old. How many of them will be new to you?

    Recorded: 17 Mar 2022

    Hey, my name is Michelle Hirsch. I'm the head of the MATLAB product management and product marketing team. My team works with the software developers at MathWorks to make sure that each release of MATLAB is better and more useful than the one before.

    Hi, I'm Heather, and I'm actually on Michelle's team. I focus on data science in MATLAB.

    We're so glad to have you join us today. We've got two goals for our talk. The first, of course, is to show you 21 features that you need now, to show you some of our favorite features that we use every day in MATLAB, and that we hope you'll be interested in trying out for yourself.

    The second is to pique your curiosity, to encourage you to ask the question. Maybe there's a feature in MATLAB that already does what I'm trying to do, where they help me do this in a better way.

    Now probably not surprisingly, but Heather and I, and our other co-workers, communicate with each other a lot through MATLAB. We make and share plots, and scripts, and apps. But I find that I typically need to walk somebody through what I've done, to explain this is what this means by this plot, et cetera.

    But not anymore. With the live editor, I can write MATLAB scripts that look like this. This is some analysis that Heather and I have been doing on the magnitude and location of earthquakes around the world. With live scripts, I can include richly formatted text with hyperlinks, embedded images, and embedded equations that I can edit with this convenient equation editor. And of course, it's MATLAB code. There's MATLAB code here.

    So I run the code, the output is immediately right here in place, and it's richly interactive. And so I can zoom in and pan around. So here we see a plot of the latitude and longitude, the coordinates of earthquakes around the world.

    And you'll notice that as I interactively explore my plot, this code here on the right-hand side is automatically generated. I can click update to insert that in along with the code that I wrote by hand. So the next time I run this section, I get exactly the same output. It's a really nice combination of convenient, rapid, interactive workflows with automatic code generation, so I can repeat the work that I've already done.

    Now plots in the live editor are interactive, plots actually in all of MATLAB are now interactive. So as I pop this plot out to look at independently, I can, again, zoom, and pan, rotate 3D plots and add data tips without having to shift between modes.

    Now, this is, admittedly, not the most convenient way to look at the locations of something spread across the earth. It'd be much more convenient to look at them, I don't know, on a map. And that's now quite straightforward to do in MATLAB, with support for geographic plots. So here I'm showing what's called a geobubble plot. So it's a bubble chart, where the size of each circle reflects the magnitude of the earthquake, and it's geographic, it's plotted on top of a map.

    One thing that's really convenient, working the live editor, is by having code and output in the same place, it's really easy to make little changes to the code and see the impact that they have. So for instance, here I'm changing the values of a parameter that sets the threshold for the smallest magnitude earthquake we show in my plot.

    Now, as Heather and I walk you through the different new features, we're going to use this feature tracker app to keep track and remind us of what we've seen, and also to keep count to make sure we show you the 21 features we promise.

    The first is the introduction to the live editor for creating rich interactive scripts in MATLAB. And those scripts can include formatted text, images, and equations, and we saw that their output is embedded directly in place and is fully interactive. We popped out the plot to see that all plots in MATLAB are now interactive by default. And we touched briefly on the ability to create geographic plots in MATLAB, plotting your data on top of a map.

    Let's use that same script Michelle was using, but we'll take it one step further. And let's say we want to share it with somebody who doesn't really want to look at the MATLAB code, or we only really want them to change the earthquake magnitude and have it update the plot. We use a live control, so I'll just create a numeric slider.

    So the person, let's say it's a manager, we just want them to look at the updates. We can see this immediately.

    And if we want to take it one step further, we can actually hide the code altogether. So we can change the view in the live editor, that way they can just change the slider and update the view immediately, without looking at the code.

    Taking it another step further, we could share it with, say, that person's manager, that doesn't need to look at any of the MATLAB code, that wants a report, basically. So you can save it as a PDF, a Word document, or HTML, and then you basically have a report of what we just did.

    So what did we just see? We saw some great options for sharing, like using interactive controls, hiding our code, and then exporting as a Word doc or PDF so we can share it with others.

    That's cool, Heather. I really loved how you built on what I did. And you could take that variable I was changing by hand and just turn it into a slider to build, effectively, a little app right there, in place of the script.

    Now sometimes when I make apps, I want them to be quite a bit more elaborate, offering more flexible, open-ended workflows to the users, like this app here that we built for visualizing earthquakes.

    So this is still extending the same data set, but just giving more flexibility. For instance, selecting the date range of the earthquakes that we want to analyze; and controlling not just the minimum magnitude, but also the depth; and as I change each of these, to be able to quickly flip through and look at different types of visualizations to understand what's happening with the data, whether it's that geographic bubble chart, or maybe even just a simple table of the raw data.

    Now we built this app using App Designer, which is a feature that comes with MATLAB for building and sharing interactive applications. What we see in the center is the canvas, where we've designed our app. And on the left-hand side, we see various components that we can just drag and drop in as we design our app, for instance, adding a tree here.

    App Designer lets me layout and get things looking exactly the way I want, and then it automatically writes the MATLAB code for me. I then just fill in the details of the code to get the specific behavior that I want to present to users or to respond to user interaction.

    Once I've got the app just the way I want, there's a lot of flexibility for how I share it. I can share it with other users as a MATLAB app that they can install and run inside of their version of MATLAB, just like I did a moment ago; as a standalone desktop application, that runs with no MATLAB installed; or my favorite way, as a web app. So I can just push this out to a web server and it's available for anybody in the organization to run directly from their web browser.

    And that's what I'd like to show here. So I'm switching from MATLAB to Google Chrome, which is my web browser of choice. And the story here is it's the same app. The same interactions, the same ability to explore all the data visualizations, all right here, built-in.

    So what have I shown you? A couple of things. We saw App Designer, for building and sharing interactive apps, and we saw the ability to share those apps as web apps directly accessible from within a web browser.

    Let's talk about data, it's kinda my thing. But we're not going to talk about the fun stuff that'll make you famous, like deep learning, or machine learning, algorithms-- we're going to talk about all the things that will lead you there, like cleaning up the junk in your data, the preprocessing, and data prep that you need to get to that point.

    We have energy data, that we're using from New York state, that we'll bring into MATLAB. So we're going to readtimetable. This is actually time series data. We have a time stamp, and then the data information for each county in New York state. So we'll select our data.

    And then you notice some live function hints. So something like [? readtable, ?] which I'm pretty familiar with, I don't need to go to the documentation, I just need a reminder of what options I have. Super, super helpful.

    So I'm using a timetable, we'll talk more about this in a second, but we'll bring it in and you can see that there's a time stamp, and then each county and the data that is associated with that county for that time. So timetables are great for dealing with data like this. They have the time associated, and so will be able to use that throughout.

    So we haven't seen this data before. I don't know about you, but the first thing I want to do is just take a look visually. So we can take a look at the plots tab, actually. I don't know if you know about this one. This is actually a long-standing feature that is really super useful for visualizations like this. You can take a look and see all of the visualizations that are available in MATLAB.

    And then if you select the data, so our energy data that we just brought in from MATLAB, we can actually see what plots are available for that data. So in this case, I'll use a stacked plot, super helpful because it shows all of the variables as a function of time together. So as you can see here, we'll talk about some outliers, some missing data, but it's really handy to be able to see everything in one place and just get a sense of what we're working with.

    So let's go back to our script, and we're going to work with our data some more. So let's look at one county. We looked at everything all together, but let's just dig into one. And so you notice there are definitely a few outliers here that we probably want to take a look at, and then there are a lot of zeros. In this case, zeros are actually missing data points. So that is important for us. We need to be able to handle missing data points, and deal with them appropriately.

    And there are some great functions in MATLAB, recently, that will help you do that. So for example, standardizeMissing, we can change those zeros to missing data, and then we can fill them with linear interpolation.

    So we removed some of our missing data, but we still have these outliers. So we'll take care of those now and just try to remove some of them. So let's run this line of MATLAB code. I don't know about you, but this looks like a very strange line of MATLAB code. Let's see if it runs. Sure enough, it does. And it gives me this awesome plot that shows me my outliers, and which ones were clean and filled.

    I'm also going to dazzle you with a bunch of features in one second. So I'm going to put the output on the right so that I can make some updates and look at this all together. And I'm going to expand this because this is actually a nice little app that I can use, it's called a Live Editor task. And I can update some of these things.

    So in this case, it's using linear interpolation or median method. I want to see what's going to happen if I use a different method. And so you can quickly change these and see what happens in the plot. It's very, very useful. It also includes the code. So everything that you need to do the outlier detection and filling and the visualization is there for you, whenever you need it. So these are super helpful. I love using these for these data processing tasks that are very iterative.

    But we'll pause here because we showed a lot of stuff, and I want to take credit for them. One is the function hints in the Live Editor, so we saw that was super helpful; timetables, near and dear to my heart; stacked plot, very useful; our plots tab, which has been around for a very long time; missing data functions; and then our Live Editor tasks and side-by-side mode that we were able to use very usefully.

    Yeah, that's a really interesting analysis, Heather. And I saw something in the data that I'd like to dig into, just a little bit further. Trying to better understand the periodicity of what's happening as the data varies over some repeating pattern.

    So what I'd like to do is look at the data in both time domain and frequency domain. That, as you can imagine, is a really common task in MATLAB. Now, any time you're doing some common task in MATLAB, I encourage you to take a peek at the Apps tab.

    This is where we went before to launch our earthquake visualizer, but the Apps tab includes up to 100 apps from various math MathWorks products for simplifying all sorts of common tasks, whether they're for developing machine learning classifiers or deep learning networks, designing and analyzing control systems, or doing signal processing, analysis or communication system design.

    That's where I can find the Signal Analyzer, which has become my go-to for working with time domain and frequency domain data. Here I've got the data that Heather had just cleaned up. I can just drag it over to import into the app. And it's a timetable, so I can drill down and select which variables I'd like to look at.

    So let's look at a time domain plot on the Dunwoodie county. We can zoom in and try to see what's happening here, would look at the different frequencies of data involved and pan around. Then also look at this in frequency domain on the right-hand side.

    Because I'm trying to understand that low-frequency variation, we'll zoom down into the lower frequency range, throw in a couple of data cursors, and just get a quick and dirty ballpark estimate of what's going on. If we look at these first couple of values, we see they're at around 0.04, around 0.08 cycles per hour. Which, if you invert those, translates to once every 24 hours and once every 12 hours. Which is, I'd say reasonable for what we might expect when we're working with energy consumption data.

    Now, Heather and I have both showing you several ways of working with data and problem solving interactively in MATLAB, but of course, what we all love about MATLAB is the access to the flexible programming language. So we can do anything we want and automate our workflows. And the same thing is true when we're working with apps. We can do things interactively, but we can also generate MATLAB programs.

    For instance, here I'm generating a MATLAB program automatically to select a region of interest within the time domain, and then perform that same spectral analysis in the frequency domain.

    So what have we seen? We've seen a couple more things, the Signal Analyzer, my go-to for working with time domain and frequency domain data, and, more generally, apps, almost 100 apps that come with MathWorks products for working through all sorts of common tasks.

    Thanks, Michelle, super helpful. I love using the apps in MATLAB. We're going to take a break, have some fun, and we're going to take some pictures. You can actually use my webcam in MATLAB and take a picture.

    So I actually want to build a little filmstrip or something you might see from a photo booth, with a bunch of pictures. I'd use subplot, but I don't know how many pictures I want ahead of time. So I'm going to use what's called tiled layout and it'll allow you to add them.

    All right, so I can add another picture. And I will use the parent as the next title. So we could do this all day, but you get the idea. And if I wanted this to look more like a photo booth output, I can actually remove some of this white space. So I can do this through the tiled layout. So I can remove our tile spacing and padding. This gives you an idea of some of the options you now have with tiled layout that are really, really helpful.

    Last but not least, I'm going to add a label. Notice that it actually spans both pictures. That's super, super helpful, again, for analyzing, and labeling, and visualizing all of this data, not just photo booth pictures like I've shown here.

    So what have we just seen? Some great stuff, actually. We looked at the webcam connectivity and then tiled layout, super helpful, the new subplot, and titles and labels across multiple axes.

    Very nice. I love how easy it is to connect MATLAB to webcams. In fact, MATLAB works with lots of hardware, not just webcams. I can go to the Add-ons menu in the tool strip, click down, and say, get hardware support packages. And here I find literally hundreds of different options for extending MATLAB and Simulink to connect to hardware.

    So for instance, say I would like to work with my Arduino board for fun projects on the weekend, I'd click in and install, and it installs the support package along with any necessary drivers that I need to get this up and running very quickly.

    Now, the window I'm in allows me to see hardware, but actually so much more than that. It's called the Add-On Explorer, and it gives access to all MathWorks add-on products, and just as importantly, to literally tens of thousands of community-authored submissions, from toolboxes to apps, to scripts, and white papers. I can browse to find all these extensions to MATLAB, or examples of people solving problems that are interesting to me.

    So for instance here, I can drill down into what's available in the sciences, and we see a lot of the most popular submissions today are related to understanding the spread of COVID-19. I can drill down, learn more about any individual submission, see what's included in it, and then quickly add it to my MATLAB, and it's ready to use right away.

    So why did we see here? We saw hardware support for MATLAB, the ability to connect MATLAB and Simulink to hundreds of types of different devices, and the Add-On Explorer for getting access to tens of thousands of community-authored submissions, plus MathWorks add-on products. Really, the Add-On Explorer helps you answer the question, surely somebody else must have done this in MATLAB before me, can I start from what they've done?

    Well, I think we've surpassed our goal of 21 features, so hopefully, you're excited to go back and really start trying some of these things out. But you might be wondering if some of your code that you wrote a long time ago might work in MATLAB these days, in the latest and greatest. So I'll show an example of some code I wrote back in grad school for classification of blood pressure information, from MATLAB.

    So it shows an error that it is an unrecognized function or variable, treefit. And I can go straight to the line that is causing the error. And this is helping me via the code analyzer, and you can see some of the warnings and errors here on the right. It'll underline, with a little squiggly, anything. You can see that, yes, sure enough, this has been removed, and it gives me an indication of what function to use.

    So I'm ready to go ahead and update. I can use what's called the code compatibility report. And I'm running this on the entire directory, and it shows me any functions that might cause me issues or are not recommended anymore. And then it also gives an indication of the line that it was occurring in, like we saw, and then the documentation links for how to change it and to help you out.

    So I went ahead and took a stab at changing this, and let's go ahead and look at some of the lines that I changed, or some of the code that I changed. So I can use the code comparison report, and this gives a nice indication of each and every line that I changed and what it was changed to. So very, very helpful for updating, and for things like source control, and just looking at different versions of files.

    So let's take a look. We've looked at some great features for going ahead and updating with all these great features, like the code compatibility report, the comparison tool, and finally, the coding analyzer.

    Phew, I think we're just about done. Hopefully, we've shown you plenty of features that you're excited to go out and try out right now, and hopefully, we've piqued your curiosity so you want to learn what else is out there.

    You surely know about the release notes, and so you can always go to the release notes and figure out what's new in each release. But let's say you're moving from release 2018a to release 2020a, and you're really just interested in what's happening in graphics because that's where you spend a lot of your time.

    It used to be that you would have to open the release notes for '18b, and then flip through and find the section on graphics, and then go to the section for the release notes for '19a, find the section on graphics, et cetera. Well, we realize it's really common that you want to focus your energy just on a specific section and specific set of releases. So we've made that way easier in the release notes.

    You can now go down and filter. So I say, only show me the release notes for graphics and only show me the release notes for the ranges I care about, let's say from '18b to '20a. And now I've built, effectively, my own little mini-personal release notes that help focus on just what I'm trying to do today.

    And so I think that's enough. That's 28 features you need now in MATLAB. Thanks very much, and have a great day.