MATLAB Without Borders: Connecting your Projects with Python and other Open-Source Tools - MATLAB & Simulink
Video Player is loading.
Current Time 0:00
Duration 51:43
Loaded: 0.00%
Stream Type LIVE
Remaining Time 51:43
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 51:43

    MATLAB Without Borders: Connecting your Projects with Python and other Open-Source Tools

    Overview

    Join us in this webinar where we will explore the vast world of possibilities that MATLAB offers when combined with some of the most popular open-source tools in the field of engineering and science.

    In this unique event, you will discover how MATLAB, a leading platform for numerical calculations and data analysis, integrates with open-source languages like Python and C/C++. Also, you will learn how MATLAB can be used within Jupyter Notebooks as well as the Visual Studio Code IDE, creating a robust ecosystem for solving complex interdisciplinary problems. We'll show you the latest features and how you can take advantage of these integrations to optimize your workflow, improve team collaboration, and take your projects to the next level.

    Highlights

    What will you learn?

    • Advanced techniques to integrate MATLAB with other languages like Python and C/C++, taking advantage of the best of both the MATLAB Platform and open-source languages.
    • How to use the MATLAB kernel in Jupyter Notebooks to document and share your analysis.
    • How to edit, execute and debug MATLAB code in Visual Studio Code.

    About the Presenters

    María Elena Gavilán is a Technical Program Manager at MathWorks, supporting researchers and educators in engineering and science. Given her technical expertise with several engineering tools and languages like C++, Python and MATLAB, Maria supports projects that seek to increase the use of MATLAB alongside Open Source in academic and research projects worldwide, particularly in applications involving AI and physical modeling.  María has extensive industry experience in numerical simulation projects (CFD and FEA) in the automotive and aerospace industries. Her areas of interest currently focus on autonomous aerial vehicles, turbulence modeling, and climate change mitigation. María holds a BSc in Physics from the National University of Colombia, a MSc in Aeronautics and Astronautics from Purdue University, and an MBA from the University of Illinois at Urbana-Champaign. 

    Mike Croucher is a Community Developer advocate at MathWorks with over 25 years' experience supporting researchers in a range of languages including Python, C++, R and, of course, MATLAB. In academia, Mike was the co-founder of The University of Sheffield’s Research Software Engineering group, one of the first such groups in the world and has been a supporter of the Research Software Engineering movement since its inception. At MathWorks, he is author of ‘The MATLAB Blog’ and focuses on Open Source, High Performance Computing and Research Software Engineering workflows. 

    Recorded: 27 Feb 2025

    [MUSIC PLAYING]

    Hi, everyone, and welcome to our webinar, MATLAB Without Borders. We are here today to explore and advocate for different ways you can connect your projects in MATLAB and Simulink with open-source languages and tools. We are welcoming you from our headquarters in Natick, Massachusetts. And today, I'm super happy to welcome my colleague and friend, Mike Croucher. Welcome, Mike.

    Hi, María. Thank you so much. So yeah, hi, everyone. I'm Mike Croucher from the UK. I'm a community developer advocate, which pretty much means I spend most of my time online and in person helping you guys make the best use of our tools and services, and also listen to various feedback that you've got about MATLAB and feed that back into development.

    And it's really great to actually be here in person with you, because María and I have done a whole bunch of these kind of presentations but always with me in the UK and María over here in Natick. So it's great to actually do one of these in person with you today.

    Yeah.

    Hey.

    Hey. And this is awesome because we'll have a session that is packed of hopefully useful tips and tricks and a lot of our sentiments also around this topic, which absolutely, we hope will impact the work that you do with MATLAB and Simulink.

    A little bit about myself-- I'm María Gavilán. I'm part of the Edu Global team here at MathWorks. I actually work with a lot of academics who make use of MATLAB, Simulink, and other tools in their projects, not only in education but also in research, and have the fortune to actually do a lot of work with open source and how our platform and ecosystem actually works so much closer with the open-source community. So super excited to have you all here.

    And now to get us started, we thought that maybe we could have a very quick recap on some of the experiences we've had by using not only MATLAB, Simulink, but likely other tools. So, Mike, in your professional practice and your journey, maybe you can share quickly with us what tools and languages you have used for your projects.

    Yeah. So I worked in academia for well over 20 years before I moved over to industry. And I was with various companies before I joined MathWorks. And I think it would be easier to say which languages haven't I used professionally in one point or another.

    And I found that it's not so much-- so I've obviously got my favorite languages. There are some technologies that I prefer to use over others because of my expertise, because of philosophical ways that I feel about the language and so on. But I found that what tends to define the language that I end up using in a project is what my colleagues want to use.

    And then you also have the fact that when the projects get big enough, you get some people, they love doing R. And then other people, they love doing MATLAB. And then other people that think if it's not in C++, then it's not a proper project or anything. You get this kind of thing. And so being able to have some kind of interoperability can be key to the smooth running of these kinds of projects.

    Now, but likewise, I mean, in my professional experience, before I even was with the MathWorks, I used to do a lot of computational fluid dynamics for automotive and aerospace applications. And very much like you, at the university as well as later on in industry, there are many languages and tools that you use. Basically, you have a full toolkit, where for the right job, you basically pick the tool that is going to make your work more efficient or likely is going to give you a little bit of advantage to make sure that your project is going to run smoothly.

    And another key piece that you mentioned, Mike, is the fact that oftentimes, we're working with teams that are very diverse, meaning likely, they have different preferences. Maybe they different languages, different tools. And it's totally OK, as long as we know how to work together and likely avoid reinventing the wheel when we're working on our projects.

    So our session today is really meant to be about this idea of working in projects, meaning we are trying to really tackle a very particular problem. And then all throughout that solving the problem, we find different tools in this toolkit that will help us actually get the problem resolved and actually get a really cool project outcome at the end of it. So that's going to be really at the core of what we'll do today.

    But to get us started, it is important for us to really chat a little bit more about the relationship between proprietary software like MATLAB and open source. So why don't we start there? What are our thoughts regarding MATLAB and open source? All right. So the question for you, Mike, is, what does open-source software mean to us at MathWorks?

    Yeah. So yeah, thank you, María. I think the way that I like to think about the relationship between MathWorks and open-source software is by splitting it into three different categories. And they're shown on this slide here.

    So to start off with, you have a certain amount of open source that's built on top of MATLAB. There's a very large community of open-source software builders who use the MATLAB and Simulink platform. And then they use that to realize something else. And they make it freely available to people.

    And then you've also got this idea of open source within MATLAB. Like most modern software packages, MATLAB is built on top of a lot of open-source components. And we interact with the communities of these open-source components in various different ways. And we'll talk about that more later.

    And then the final thing, and something that we'll be talking about a lot today, is open-source software alongside MATLAB. So this is stuff that interoperates both with MATLAB and Simulink so that you can use them together as seamlessly as possible to get the benefits of both worlds.

    Yeah, no, this is amazing. But something that is worth clarifying here is that when we talk about open source, we're basically talking about a mindset, a philosophy of making sure that you're, in a way, making stuff available, accessible, and all of that kind of thing. So that's why we have these three ways to do so.

    Exactly so. That's right. Yeah.

    This is awesome. Yeah. And definitely, this is part of what we'll be showing in our session today. But we wanted to give you this very quick overview, because it's a good way to start this conversation about MATLAB in the context also of open source.

    So that being said, of course, many of you attending this session might be wondering, well, why MATLAB, in the first place? And essentially, this leads us into MATLAB itself-- oftentimes, we know MATLAB just as a language. But it turns out that MATLAB is more than a language, isn't it, Mike?

    Absolutely. I mean, I, along with many other people at MathWorks, consider MATLAB to be a whole platform of things. It's so much more than just a language. The obvious distinction is that people will say, it's not just the language. It's also the graphical user interface. That's the obvious first thing.

    But then we've got things like Simulink. We've got some MATLAB Coder, which is used heavily in industry to convert MATLAB code to C and C++ code, and so on. We've got all of the products that help with safety standards and help so that you can adhere to that. And it just goes on and on, and Simscape and various other things. So it's this huge platform of things of which the language is part.

    Yes. The language is that foundational layer. But we have more than 130 toolboxes, I mean, to begin with. So it gets very specialized. And that's part of the beauty of having all these different things that you can use in your workflows, which essentially means if you're already using other tools, languages, this is really meant to augment a lot of the work that you're doing. So it's one of the reasons why we encourage you also to think about from that perspective and all the good stuff that you can actually do with MATLAB and Simulink.

    So let's chat about the agenda for today. So we're going to really focus on projects. We mentioned that from the beginning. So essentially, we're going to be working on three very specific projects.

    And before we get started, we're going to really chat more about some initial steps of what you should be doing as best practices when you're starting to work on projects. So in the first one, Mike, we're going to talk about GitHub. So why GitHub then?

    Yeah, thanks, María. So I don't know about you guys or-- but I found that very often when I first start collaborating with somebody, they'll email me a script. They email me the script. They email me their data. And then we get started from that.

    And then if you've got two or three people, these scripts start getting emailed around to each other. And you quickly end up with a mess. You see this thing where it's something like analysts_version1.m_version2. And then there'll be one that will be _MikesVersion, which I'll send to you and you send back to me with "fixed" because the one I sent to you was broken, and so on and so forth.

    And then you have the fact that once you finished your project, you somehow need to disseminate it. And for me, the solution to all of this is to use Git version control and GitHub.

    Awesome. So that's basically what we're going to do first. Right?

    Exactly.

    So we want to show you the step by step. So what we're going to do now is then focus briefly on some of the good practices when you start working with Git and GitHub and essentially when you connect MATLAB with all of this. So let's start there.

    So let's take a look at an example of an analysis that I might want to share with other people. So here, I have MATLAB. And inside this folder, I've got some data about sunspots. And I've got a script that performs an analysis on that data.

    So this looks like a lot of the type of research scripts that you may have seen or even created yourself. If I double-click on this, I can see the script and everything that it's doing. I've got some comments. It doesn't look too bad.

    If I run it, then it produces a bunch of plots. Figure 1, figure 2, 3, 4, and so on. And I can look through those. And if I refer back to the script, I can see what these figures are actually showing me.

    Now, let's imagine that I want to share this with the world. Now, in an ideal situation, you would have this under version control already with Git. But showing you how to do that would be the subject of an entire webinar, I think, of its own. And so what I'm going to do is show you the absolute bare minimum to get into a slightly better place by using GitHub in the first instance.

    So the first thing that you're going to need to do is sign up for a GitHub account. Now, these are completely free. So there's no reason why you shouldn't go ahead and do that. And if you want to follow along with the rest of this session, then you're going to need a free GitHub account. So go ahead and sign up for one if you don't have one already, or sign in if you already have an account.

    Once you've done that, we're going to need to create a new repository. So here I am. I'm logged into GitHub with my username MikeCroucher. And I'm going to click on a new repository.

    Give this thing a name. Let's call it sunspots. And it's my repo for my sunspot analysis. In the first instance, I'm going to make this private so that only I can see it. And when I'm ready, I can easily change it to public and open it up to the whole world. But I'm going to do this on private for now.

    I'm not going to create and add any extra files. I just want to create a completely empty repository. So let's go ahead and do this. So I now have my empty repository.

    And if I was using a Git version control, then there are command line ways that I can start to add files to this. But I'm starting from the very beginning. I'm assuming that you've never used Git before. So I'm going to show you the very simplest way to get some code from MATLAB and onto GitHub.

    And what you do is from this page here, we just click on Uploading an Existing File. So let's do that. And then it says, I want to drag some files here to add them to repository. So a very easy way I can do that, if I just move this browser window to the right, I can see my MATLAB files here. Let's click on this sunspot analysis. Drag it over to here. And then my sunspot.dat, drag it over to here. And then commit changes.

    And there it is, done. I've got those files now in a private GitHub repository. And that is the simplest way of getting something onto GitHub.

    Now, even if this is all you do, it's still a reasonable start and a lot better than many people. You see, even today, it's a sad fact that a lot of people who do computational research or data science or whatever and publish papers in various fields, they don't share their code and data. And this is a big problem.

    So even if this is all you do, it's a great start. But you can do so much more. And you don't even need to leave the GitHub user interface to start doing a little bit more.

    One of the first things I would recommend is to add a README file. So we just click here to add a README. And we can start actually adding some information about what these files are, what the analysis is, and so on and so forth.

    And you do this in something called Markdown. And here's an example here, where I create a title and a link, and so on and so forth. And I can preview what that will look like. And then as I'm writing, I can just click Commit Changes whenever I finished. And I can steadily start improving this GitHub repository.

    Going back over to MATLAB, another upgrade that I want to make is I want to move from this traditional MATLAB script to something that's a lot richer. And that is a live script. So if you've not seen live scripts before, they can contain code, just like a normal script, but they can also contain text, graphics, movies, animations, all sorts. So it's a much richer experience for whoever's running your analysis.

    So just to very quickly give you an example of the kind of things you can do, let's create a title. I'm copy and pasting this from somewhere else so you don't have to waste your time watching me type, if you just want to get the idea. So we do a title. Let's add some text. And then we can add some code. So let's take that from our original script, the loading and plotting section.

    There we go. And then when I run that, it either goes on the side there, or I can move it in line like this. And with a little bit more work, I can end up with something like this. So now I've got the complete analysis in this live script. All of the code, the results, and the plots, some nice text and so on, complete description.

    And then I can use elements of this to improve the README file in GitHub. So let's go back over to GitHub. And so with a little bit more work, I can end up with a README file that looks like this. So this includes text that explains what's going on with this code and data. What is this repository for? What's it doing?

    I've got some explanatory text explaining some of the history, links to further reading. I've got code. I've got images and so on and so forth. So this is a much more richer experience for anybody that comes to this GitHub repository.

    And I've got one other little trick up my sleeve as well. So I've got this thing here-- run this analysis in MATLAB Online, and then this little badge. And if someone clicks on this, then this will open up a MATLAB for them.

    And when MATLAB Online opens, it gives me the opportunity to copy these files from the repository. So I click on the disclaimer. I understand the risks of saving and running code from an outside source. It's my code. So I'm very happy with that. I click Save and Open. And it gets the code and data from GitHub for me. And it opens up the live script inside MATLAB Online.

    And so now I've got full access to all of the data and the analysis that was shared on GitHub. And I can also execute it as well. So I can do everything here that desktop MATLAB can do. So let's change this plot to red, for example, just to show that I'm actually running code for real inside my web browser.

    One of the things that I really like about this workflow is that this makes my complete analysis, all of the code and data, absolutely everything, accessible to everybody in the world, even when they don't have a MATLAB license, as described in this blog post that I wrote here back in 2023.

    So there's still an enormous number of things that we could do to improve both the code and this GitHub repository. But if this is all you do, then we've still made a pretty good start. We've made the code available to the world so that they can download it. They can use it themselves in the web browser or on their own machine, whatever they want to do. We've opened up our analysis to the world. And so this is a great start. And with that, we'll move on with the rest of the webinar.

    All right. So we got this first step done. And actually, it's funny because it's like step zero. Yeah, so to ensure that as we're starting to work in our project, Git and GitHub becomes part of essentially this toolkit and good practices.

    So now we're going to really dive in into the projects. And for project number one, actually, we have chosen something that is really, really fun. So maybe you've seen in the news that the solar activity in 2024 was pretty intense. You have seen that, Mike, in the news?

    Yeah, I've even managed to see some of the aurora as far south as the UK.

    Ooh, wow.

    So yeah, it's been fantastic. I've never seen it before. I was going to have a big trip to go and do it. I don't need to now. I just saw it from my bedroom window.

    Very interesting. So that's pretty cool and showcases the fact that, yes, we've been going through this peak of solar activity in 2024. In 2025, it's meant to continue, actually. But we thought about actually exploring a little bit more information about solar activity, solar flares by using Python and MATLAB. So why don't we do that as our project number one? And yeah, you will have the opportunity to not only watch it but then repeat it afterwards. So let's go with project number one.

    The solar activity cycle is an 11-year cycle where the sun's magnetic activity fluctuates between calm and stormy states, known as the sunspot cycle. This transition impacts Earth, affecting the ionosphere and causing phenomena like the northern lights and radio communication disruptions. We track space weather using satellites. In this project, I'll demonstrate how to query data from geostationary satellites, using the Python package SunPy, and document my analysis in MATLAB. Let's dive in.

    First, I access my GitHub repo. Version control is crucial for tracking changes and collaborating effectively. In MATLAB, I navigate to the Source Control option. Select Git. And provide my repo URL.

    When I retrieve my files, note that all files appear green in this Git column. Let's open the MATLAB script for the notebook with my initial analysis. I add context to my analysis detailing solar flares. During solar storms, high velocity particles cause solar flares, impacting Earth's ionosphere.

    X flares can cause radio blackouts, while M and C flares may disrupt communications. SunPy is an open-source solar data analysis tool in Python, integrating with packages like Astropy and NumPy. Before using it, I confirm I have access to both MATLAB and Python. For a list of compatible versions, don't forget to check this page.

    I ensure MATLAB recognizes my Python environments with the py m function, allowing seamlessly Python code execution in MATLAB. But sometimes I may have more than one version of Python installed. Maybe I have different virtual environments. So I can use pyenv to point MATLAB to the right Python version I want to use.

    The next quick check is to confirm that I have the packages installed. Here, I'm quickly checking that NumPy and SunPy are properly in my system. And moreover, I can check further information about SunPy.

    Once all of this is confirmed, I can start using Python code in MATLAB. And the syntax to do so is straightforward. We start with py dot, the package or module name, and then the function name. Note that here, I'm not using import to bring the Python package.

    So I can do something very simple, like getting the square root of a number by simply doing py.math.sqrt and then the number. And there is much more in terms of syntax and data type conversion. So definitely the documentation is going to give you a lot of good examples and tips.

    But likely when you are working on a more complicated task, you don't have just a few lines of code. Likely, you have already a Python script, like the one I have here. Let's take a look.

    Notice that here I'm able to browse my Python code. And I have syntax highlighting. Here in my code, I'll use SunPy to query the data collected by instruments on the Geostationary Operational Environmental Satellite, or GOES, operated by NOAA in the US.

    First, I'll provide a time frame to console solar flare events. And I can start preprocessing data obtained so it's filtered. I can then convert it to a pandas DataFrame. And I can the output based on the magnitude of the solar flares detected.

    A feature I find handy is a live editor task for executing Python code directly in MATLAB, simplifying complex analysis. Here, I select Run Python Code. And I can select the relevant output variables that will make more sense for my analysis.

    I want to choose just a couple to get an idea about the resulting data. I will then click to run this task. And while this runs, I can check the code generated. Well, let's take a look at the output.

    I get a full detail on the type of Python variables I get back. At any point, I can also check this in the MATLAB workspace. Now, let's take, for example, the pandas DataFrame and convert it into a MATLAB table that I can use right away in my analysis.

    This is great. But now I want to do some additions to make the code more interesting. I can go back to my Python code right here in the MATLAB Editor. And then I can start adding a segment of code that will select a specific day, gather data from the two X-ray sensors known as XRS. That will give me more information about solar X-ray irradiances for different wavelength bands.

    So we have typically a short channel and a long channel. And this is key because the magnitude of the flare, also known as the flare index, is defined based on the 1-minute average of the XRSB channel, the long channel, and all of these analyzed at the peak of the flare. So let's add this to the segment of code to my Python script. I'm going to now work with a time series. And then I'm going to return to my MATLAB script to refresh the list of output variables so I can collect this new information that I'm adding to my Python code.

    Now, I have the output of the maximum XRSB value for the solar flares on that day. And this information, alongside the time series data, can be very useful to find patterns or trends and even calculate probabilities of C, M, or X flares happening.

    A quick note on the impact on radiocommunications. Given that X-rays from solar flares completely disturb the ionosphere, I could take my project to the next level and perhaps come up with ideas to do some real-time processing of the signals received by ham radios or even software-defined radios.

    As an example of the impact, let's take a quick look at the broadcast from one of the two test signals that NIST in the US maintains in support with Ham Radio Citizen Scientists. For instance, one of the stations located in Hawaii on a normal day will actually provide a test signal that sounds like this.

    Inquiries regarding these transmissions may be directed to the National Institute of Standards and Technology. Radio station, WWVH. Post office box 417, Kekaha, Hawaii. 96752. Aloha.

    [PULSING]

    However, on a day where there is an active solar storm, maybe C or even M, you would hear something like this.

    Inquiries regarding these transmissions may be directed to the National Institute of Standards and Technology. Radio station, WWVH. Post office box, 417. Kekaha, Hawaii, 96752. Aloha.

    [PULSING]

    I could visualize audio signals from ham radios during solar storms. For instance, I could use the Signal Analyzer app in MATLAB just to do a first examination of spectra and spectrograms. I could start laying the groundwork for potential digital signal processing projects.

    Now, I can export my live script to both Markdown and Jupyter Notebook formats. The Markdown I can use to update the README file of my GitHub repo. And I'll come back to the Jupyter in a moment.

    Now, remember that I mentioned this column with the Git status? Look at some of the files. They were modified. And likely, I want to commit and push changes. When I view and commit changes, I can decide if I want to keep changes in all files. And then it is very important to push the changes. This prompts a dialog where you need to provide your GitHub credentials or a token.

    Finally, let's chat about the generated Jupyter Notebook. The official MATLAB integration for Jupyter enables you to code in MATLAB directly in Jupyter, one of my favorite open-source projects. Here, I have JupyterLab. And once I have the packages needed, I see the option of the MATLAB kernel as well as this Open MATLAB. When I click this one, it opens a web version of the MATLAB IDE on a separate browser tab.

    When I open the Jupyter Notebook generated from my project, I get to see a combination of Markdown language and cells with MATLAB code. Notice how here it specifies the MATLAB kernel. And I can start executing code cells. Try it. And always share with us your feedback.

    I hope you enjoyed this project. And remember, with another solar activity peak in 2025, there is a lot to explore. Have fun. And share your thoughts and ideas for further improvement.

    All right. That was pretty awesome with project number one, don't you think, Mike?

    Yep.

    So let's now move into project number two. And for project number two, we want to do things a little bit differently. So in project number one, we show you how you can bring some of your Python code into MATLAB and then how in MATLAB you can do a few other interesting things. But now I'd like to do the other way around, which is, what if you're doing something in Python and likely you want to bring some MATLAB capabilities? And for that purpose, Mike, have you ever heard of PyTorch?

    A little bit, yes.

    [LAUGHTER]

    So for those of you who are probably acquainted with it, PyTorch is one of the very popular frameworks for deep learning. And indeed, you can use PyTorch in MATLAB and Simulink. So for project number two, we're going to focus on that. So let's go now to project number two.

    For this project, we're now going to focus our attention on artificial intelligence, which is a mega trend that is used in industry but also in research. There is a lot happening. Likely, you have heard about terms like machine learning and others like deep learning, reinforcement learning, and so on.

    Now, something that has happened in the last few years is that there is a lot of system design that is AI driven. And this is why it becomes more important to actually think about all these different models that can be used, for instance, for deep learning. I'm not going to explain all the details about deep learning. But it's important to know that there are many techniques. And there is a whole zoo of different frameworks and different models that can be used.

    Now, for the purposes of our projects, I'm going to focus on the interoperability between MATLAB and Python for AI. And more specifically, I want to then now focus fully on PyTorch. So that's what I'm going to do in my next project.

    So I'm starting here with my JupyterLab session. And I can also run this example or continue with my project in Visual Studio Code. But for the sake of this specific example, I'm going to stick with Jupyter Notebooks.

    Let me now open the notebook that I have brought from my GitHub repo, because yes, again, I'm tracking changes and making sure that I'm committing to the updates that I'm making to my project. And now what I'm going to do is basically work with a notebook that is using a Python kernel.

    So in this project, I want to then start doing some image classification and maybe one example with object detection using pretrained models. For this very specific project and example, I'm going to use mainly PyTorch. And I'll bring later MATLAB and Simulink for some augmented capabilities so I can explore ways to improve the model.

    So let's dive in. First things first, I'll have to bring some packages of course. And maybe I want to start by taking a quick look at the specific image that I'm bringing along. So you'll notice that I do have an image that of course, has been resized and preprocessed a little bit. But it's pretty much just a scene or scenario where I have some cars. I have a pedestrian. I have a traffic light. And this is an image that I want to start using to, again, do some fun operations and some fun things with deep learning.

    So with that in mind, I thought one of the first nice experiments that I could try is to actually detect and classify objects in the image. I know this is a little bit more advanced, because the first step likely would be image classification. But I really was curious about what a pretrained model will do for me when trying to identify and draw some bounding boxes around different objects.

    So I've heard about this architecture called the Mask R-CNN ResNet-50. And I thought, OK, why not bringing it along? So every time you work with PyTorch, then you'll have to not only work with the package for torch or bring that package into your code. But also, you'll bring up the different models and transforms using torchvision, because that's exactly the type of problem we have right here.

    I'll bring the pretrained model for the specific architecture I'm interested in using. Of course, I have to start evaluating the model, because when I'm working with PyTorch, I'm essentially working with tensors, which again, is another advanced concept. But it's a fun one as you're building your different models.

    Let's make this real quick. What I'm doing really in this segment of code is to bring my model, then bring the image, and ensure that I'm drawing some bounding boxes around every single object that the model is able to detect in my image. So let me run this. And let's see what happens once I process the image.

    All right. So this is what I'm getting back. And essentially, you'll notice that I'm-- the model is doing a pretty good job at detecting many things in the image. It's detecting not only the car in front of me and maybe the car that is diagonal to where this photo was taken. But it's also detecting the traffic light. It's detecting the pedestrian.

    It's even attempting to detect the lane, the line here separating the different lanes. So clearly, there is a lot of information in this image. But maybe that's a lot, that's too much. So likely, I'll now switch to something that will simplify my understanding a little bit further.

    So I'm going to downgrade a little bit and work only on image classification, meaning that rather than trying to detect everything in the image, I'm going to rely on architectures or models that will just give me one prediction per image. And for this, let's use the ResNet-50, which is fairly small. But it's going to give me the opportunity to then some fun things.

    Now, the other piece that it's important when you're starting to work in deep learning problems is that very likely, you'll want to then implement those models somewhere. That somewhere could actually be hardware. So oftentimes, I want to ensure that the models are pretty efficient once I need to implement them further in my system.

    So once I run this segment of code, the cell, basically, what I'm doing is not only performing the image classification, which is returning the predicted class as a traffic light. But also, I'm creating the trace model that I mentioned earlier. So now I have this in-- basically, in my files. We'll come back to this in a moment.

    So now I want to bring MATLAB and Simulink for additional exploration of the pretrained models that I'm using here in my code. The first thing I need to do is to actually import the MATLAB Engine package. So the MATLAB Engine API is going to be the mechanism that will establish that communication between Python and MATLAB.

    And for that purpose, you need to ensure that the MATLAB Engine package is installed first. So you can simply pip install that package if you like to. And then the next thing is to get the engine session started. You can connect with many different options. You can open the desktop, as I'm about to do here. You can definitely just keep it with no desktop or basically the process running in the background.

    But what is important is that you assign this to something that you're going to remember afterwards. So in this case, ENG is going to be the name of my object that will manage and will allow me to do all the calls to my MATLAB session. So let's run this. And once it runs, then you will notice that it will quickly bring up the MATLAB desktop for me.

    So I have here my MATLAB desktop. And immediately, I noticed that even the path that is being opened here is the same one from where I'm calling basically this session, so essentially where my Python file is located. A few things to get us started into how do we use the engine. I'm basically going to use this object. And then I'm going to bring the functions that I know from MATLAB to do different types of operations. So in other words, I can use the MATLAB functions.

    So for instance, why don't we take a look at the Deep Network Designer, which is a very nice app to then start exploring your neural networks. Once I'm here in the Deep Network Designer, notice that I have the option to import my PyTorch model. Given that I have already traced the model, then it's going to be so much easier for me to bring it along and then explore the architecture of the model. What I like about this app for MATLAB is that it gives me a visual way to explore the architecture of the different layers in my model.

    All right. That was a really cool project. And I'm pretty sure that for many members of our audience interested in AI and likely interested in working with things like PyTorch and TensorFlow, this might be really a nice way to take a deeper dive and try it on your own. So do not forget the examples that we're sharing as our projects. They're going to basically be on GitHub and the documentation. So we'll share the resources with you at the end. And you will have the opportunity to go through and repeat all of the stuff that we just did.

    But it looks like we're still missing something. So, Mike, what do we do for project number three?

    Thanks, María. So up until now, we've always been working in the MATLAB desktop. And that's fantastic. I love the MATLAB desktop. We've put so much effort into it at MathWorks. I think it's a really great place in which to do engineering and science.

    But when you're working in a multidisciplinary team and working with multiple languages, everybody's got their favorite language, it's very often that they're going to be using a different editor. And by far the most popular editor for programmers in the world is Visual Studio Code. And something that I've been really proud to be a part of is helping the team who have been creating the MATLAB extension for Visual Studio Code-- and I've been promoting it on social media and writing about it on the blog and so on. And the community just went crazy for it. They absolutely loved this extension.

    So let's dive into project number three, where we're going to talk about using Visual Studio Code with MATLAB in more detail.

    Wow, that's super cool. Let's take a look.

    So here, we are in Visual Studio Code. And the first thing that we need to do is install the MATLAB extension. So to do this, we click on this icon down here. And Extensions. Or you can alternatively press Control-Shift and X if you prefer keyboard shortcuts. So we click on this. And then we search the extensions for MATLAB. We make sure that we get the one that's from MathWorks. So you can see that's here. And we just click on Install. And that is it.

    And after you install the extension, you can see that it opens this document here, which gives us an idea of some of the features that the MATLAB extension for Visual Studio Code provides. So you can see that some of these features, from the basic ones, you don't even need MATLAB to be installed. So that's basic stuff such as syntax highlighting, code snippets, commenting, code folding, and so on and so forth.

    But if you want some of the more advanced stuff, then you need to have MATLAB installed on your system alongside this extension. And ideally, it should be MATLAB released 2021b or later. And another place that you can find this information is on the Extensions web page on the Visual Studio Code Marketplace. So here, we can see that exactly the same information is available here. And we'll give you this link as part of the show notes.

    Back to Visual Studio Code. So we've got the MATLAB extension installed. And let's actually do something. So I'm going to open a file. And this is a bunch of files from a GitHub repository called awesome-matlab-students. It's one of MathWorks' GitHub repositories. And it's got a set of nice, fun examples. So let's go into to here, MATLAB animations. And I'm going to choose BloomingRose. There we go. BloomingRose.m.

    So I've opened this up in Visual Studio Code. And we can see that it's got nice syntax highlighting. And I know this all looks-- this all looks very nice. And I can just run it by clicking this button over here or pressing F5. There we go.

    So it's run the animation. And I've got my MATLAB terminal here. So I can do everything down here that I can do on the MATLAB command line. So you can see what version of MATLAB I've got installed and so on.

    Something else that I can do that's very nice and was a very often requested feature when this extension first came out is debugging. And what that means is I can stop the code execution wherever I want. So, for example, let's scroll down. And I'm going to stop the execution at line 62.

    So what I do is I move my mouse just to the left of line 62. And I click, and it gives me this little red dot. And that's called a breakpoint. And then I click on this icon here to open the Run and Debug panel. I click on Run and Debug. And then I execute my code.

    And the script runs. And it then stops at line 62. And it's run all of the other lines before this. And I can see in this little workspace view here the value of all the variables so far.

    I can also just hover over a value. So let's hover over this pnum. So pnum is a double, a value 3.6. Petalsep is another double. And I can just hover over these different variables and see what their value is right now.

    Or I can go into the command line. So you see this little k here that says this is in debugging mode? And I can see what the variables are here. So let's see what the value of y is. So y is a vector. Sorry. y is a matrix even.

    And I can run whatever AI commands that I want to here. I could then say-- let's get another breakpoint here and continue code execution from line 62 to line 67. So now there's these little range of icons up here. I'm going to click on the Continue one. And it stopped at my next breakpoint.

    And then I can look around here. So now I can see that z has been defined and so on. So this is a great way of finding out what's going on in your code and just stepping through it line by line if you want to and really getting an idea of what's going on.

    And I use it all the time to help figure out why some code is not working, various ways of making code faster, understanding what's happening, and so on. So let's stop our debugging session by clicking on this Stop button here. And then over here, we-- what do we do? We click. And we click Disconnect up here.

    And the final thing that I'd like to show you with the MATLAB extension for Visual Studio Code is the integration with GitHub Copilot. So GitHub Copilot is an extension made by Microsoft. And I've got it installed in my Visual Studio Code as well.

    And it works just great with MATLAB. So to give you an example, let's say that you're new to MATLAB. You've never seen this code before and you're wondering, what does the linspace function do here? What's happening here?

    So I'm going to highlight this. And then I right-click Copilot and say, explain that line of code. And it sends it over to the Copilot Chat. And it explains what the linspace function does, that it's a built-in MATLAB function. It creates a vector of linearly spaced elements between two specified values, and so on and so forth. And it goes on to explain what's happening in this explicit case.

    Something else that I can do is I could just send a line of code to this chat. So let's send this line of code here. So I highlight this. Right-click Copilot. And add the selection to the chat.

    And then I'm going to ask it, what do the dots mean here? And it tells me here. So the dot before an operator indicates element-wise operations. So if you're new to MATLAB and you've never seen this notation before, you might be a little confused. And Copilot can help you out.

    Now, of course, there are many other things that Copilot can do. But I don't want to make this a webinar about GitHub Copilot. I just wanted to show you that everything works exactly as you might expect with the MATLAB extension for Visual Studio Code.

    And so that's it. If you want to use MATLAB with Visual Studio Code, then there's a huge range of functionality that's open to you. And I suggest you give it a try. And let us know what you think.

    So we have completed now project number three. And that was awesome. Thank you so much, Mike. And you have noticed that we are covering a lot of ground in this presentation. So we definitely encourage you to return to it. So this will be available in our website.

    And essentially, we want to ensure that you have the ability to come back and repeat a lot of the steps in the projects and take a deeper dive. So, yes, Mike, we covered a lot of it. We have resources for our attendees. And essentially, on top of the GitHub and the documentation, there are many resources on our website if you want to really get started and then do more stuff. But as we are now closing this session, what else do we want to share with our attendees?

    So I think something that I'm really interested in is finding out, do any of these messages resonate with you? In the things that we've shown you, are you looking at it and thinking, that looks great? I'm going to run with that for my next project. I'm going to use that. Or have you used it? And has it been a great experience? Or have there been problems? I really want to know both sides of the story.

    Or also, do any of you look at some of it and recoil in horror and say, what? No, I'm definitely not going to do that. And if that's the case, we want to hear about it and why and see if there's something we can fix it. So really interested in getting your feedback. So please do get in touch with us.

    Yeah. And I think that's a great point, Mike, because we mentioned open source is a philosophy. And part of it is growing as a community. And, yes, we have a MATLAB community. And likely, of course, we want to partner and collaborate with other communities.

    And for many of the users who likely-- yeah, they have other preferences in terms of tools and languages. All of this is about actually growing together. So as Mike was mentioning, regardless of the experience and anything you'd like to share with us, please do, because this is really going to help us ensure that everything that we share with you and we present it is going to get even better. So with that in mind, I have to say thank you so much, Mike. Good job.

    Thanks, María.

    All right. This was great. And we have to say thank you very much for joining this session.

    Thank you for your time.

    Yes, absolutely. And we're going to keep here on the slide our contact information in case you want to reach out. So please do so. Share with us your comments, questions, and you name it. And we'll definitely make sure to keep in touch. And likely, we'll come back later with more projects. Right?

    Exactly.

    Yes, that's the plan. All right. Thank you very much. And until next time.

    And for those of you who are joining our live webinar, do not forget that now we will move into our Q&A part of the session. So please keep it in line. We're going to now switch to the Q&A. Don't forget to add your questions to the Q&A panel for this webinar. And yeah, we'll have the final 15, 20 minutes of our session dedicated to your questions. So please send us your questions. We'll see you soon.