Programming: A Starter Project Using MATLAB with Python

Information

This curriculum module contains interactive MATLAB® live scripts that teach fundamental concepts and basic terminology related to programming computers. This module explores interactions between systems by using the OpenWeather API and calling into Python from MATLAB.

Programming: A Starter Project Using MATLAB with Python covers downloading and installing a Live Task to run Python code, accessing the OpenWeather API to check the weather, and choosing how to package the weather reports into your personalized weather dashboard.

You can use these live scripts as demonstrations in a lecture, class activities, or interactive assignments outside of class. The module is divided into two interactive scripts and an example script: setting up your environment to run Python from MATLAB in UsingPythonWithMATLAB.mlx, exploring the API with CheckingTheWeather.mlx, and the example SampleWeatherDashboard.mlx.

The instructions inside the live scripts will guide you through the exercises and activities. Get started with each live script by running it one section at a time. To stop running the script or a section midway (for example, when an animation is in progress), use the Stop button in the RUN section of the Live Editor tab in the MATLAB Toolstrip.

If you are an instructor who would like solutions, or if you find an issue or have a suggestion, email the MathWorks online teaching team at onlineteaching@mathworks.com.

Related Courseware Modules

  1. Fundamentals of Programming available on GitHub or
  2. Programming: Organizing Data available on GitHub or
  3. Programming: Structuring Code available on GitHub or

Prerequisites

This module assumes familiarity with basic programming concepts such as variables, data types, and functions, structures including arrays and structs, and control flows including if/else as well as how to use them in MATLAB. These ideas are all presented with interactive examples in Fundamentals of Programming, Programming: Organizing Data, and Programming: Structuring Code .

Getting Started

  1. Open the project file.
  2. Get started with each topic by clicking the link in the first column of the table below to access the full script example.
  3. The instructions inside each live script will walk you through the live scripts and related functions.

Products

MATLAB® and Symbolic Toolbox™

Scripts

Organization of Programming: A Starter Project Using MATLAB with Python

Script In this script, you will...
Setting up MATLAB to run Python code
  • check that an appropriate version of Python is installed and visible within MATLAB.
  • download and install the Run Python Code Live Task.
  • try running Python commands and a Python script from MATLAB.
Reading and Accessing the OpenWeather API
  • set up an account with OpenWeather to create your own API key.
  • use checkweather.py to make an API call to OpenWeather.
  • use MATLAB to explore the data returned by checkweather.py, including data type conversions, unit conversions, and data visualization options.
Example Weather Dashboard
  • use hidden code interactions in live scripts to design a streamlined user experience.

Copyright 2022 The MathWorks™, Inc.