MathWorks-Teaching-Resources / Programming-A-Starter-Project-Using-MATLAB-and-Python

A scaffolded project involving pulling and installing a Live Task and using MATLAB and Python in combination to access and analyze data from the OpenWeather web API.
BSD 3-Clause "New" or "Revised" License
24 stars 5 forks source link
api app courseware create-app cwm matlab matlab-live-script multiple-languages programming python

Programming: A Starter Project Using MATLAB with Python

View on File Exchange or Open in MATLAB Online

MATLAB Versions Tested

Curriculum Module

Created with R2024a. Compatible with R2024a and later releases.

Information

This curriculum module contains interactive MATLAB® live scripts that teach fundamental concepts and basic terminology related to programming computers.

Prerequisite Domain Knowledge

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, Programming: Structuring Code.

Background

You can use these live scripts as demonstrations in lectures, class activities, or interactive assignments outside class. 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 using the Run Python Code Live Task to run provided Python code, accessing the OpenWeather API to check the weather, extracting useful data from the API call, and using App Designer to create an app with a personalized weather display.

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 EndIcon.png Stop button in the RUN section of the Live Editor tab in the MATLAB Toolstrip.

Contact Us

Solutions are available upon instructor request. Contact the MathWorks teaching resources team if you would like to request solutions, provide feedback, or if you have a question.

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, Programming: Structuring Code.

Getting Started

Accessing the Module

On MATLAB Online:

Use the OpenInMO.png link to download the module. You will be prompted to log in or create a MathWorks account. The project will be loaded, and you will see an app with several navigation options to get you started.

On Desktop:

Download or clone this repository. Open MATLAB, navigate to the folder containing these scripts and double-click on MATLABwithPython.prj. It will add the appropriate files to your MATLAB path and open an app that asks you where you would like to start.

Ensure you have all the required products (listed below) installed. If you need to include a product, add it using the Add-On Explorer. To install an add-on, go to the Home tab and select AddOnsIcon.png Add-Ons > Get Add-Ons.

Products

MATLAB® is used throughout. Tools from the Symbolic Math Toolbox™ are used to convert between different unit systems in the weather applications.

Scripts

UsingMATLABwithPython.mlx

Introductory script
In this script, students will...
RunPythonLiveTask.png
$\bullet$ check that an appropriate version of Python is installed and visible within MATLAB
$\bullet$ explore the Run Python Code Live Task
$\bullet$ try running Python commands and a Python script from MATLAB

CheckingTheWeather.mlx

Investigatory script
In this script, students will...
WeatherStruct.png
$\bullet$ set up an account with OpenWeather to create your own API key
$\bullet$ use existing Python code to make an API call to OpenWeather
$\bullet$ use MATLAB to explore the data returned by the API call, including data type conversions and unit conversions

CreateCurrentWeatherApp.mlx

Application script
In this script, students will...
WeatherDashboard.png
$\bullet$ use App Designer to build a custom app using the code from CheckingTheWeather.mlx
$\bullet$ create callbacks, properties, and functions
$\bullet$ design and organize a UI with drag and drop elements
$\bullet$ reuse code from CheckingTheWeather in a new context

Apps

Both of these apps require running Python from MATLAB, as set up in UsingMATLABwithPython and an OpenWeather API key, as set up in CheckingTheWeather.

License

The license for this module is available in the LICENSE.md.

Related Courseware Modules

Courseware Module
Sample Content
Available on:
Fundamentals of Programming
Learn the basics of how to make a computer
accept, store, and compute with information
MouseThoughtBubble.png
OpenInFX.png
OpenInMO.png
GitHub
Programming: Structuring Code
Learn how to organize your code into functions,
debug, comment, and share
RGBTurkeys.png
OpenInFX.png
OpenInMO.png
GitHub
Programming: Organizing Data
Learn more about strings, numeric data types,
memory, and ways of storing data
SeaSurfaceTemps.png
OpenInFX.png
OpenInMO.png
GitHub

Or feel free to explore our other modular courseware content.

Educator Resources

Contribute

Looking for more? Find an issue? Have a suggestion? Please contact the MathWorks teaching resources team. If you want to contribute directly to this project, you can find information about how to do so in the CONTRIBUTING.md page on GitHub.

Acknowledgments

Many thanks to Blake Naccarato on his suggestions for improvement.

© Copyright 2024 The MathWorks™, Inc