An overview of programming concepts including arrays, strings, loops, and algorithms with a project.


Updated 27 Jan 2023

From GitHub

View License on GitHub

Fundamentals of Programming

View <File Exchange Title> on File Exchange or Open in MATLAB Online

Curriculum Module
Created with R2021b. Compatible with R2021b and later releases.


This curriculum module contains interactive live scripts that teach fundamental concepts and basic terminology related to programming computers. This includes discussion of inputs and outputs, numbers, strings, arrays, branches and loops. This content is broken into six instructional live scripts and one project where live script instructions are paired with a plain code practice script. Solutions are available to instuctors upon request.

These lessons can be used as part of a lecture, as activities in an instructional setting, or as interactive assignments to be completed outside of class.

Get started with the Fundamentals of Programming interactive examples

Option 1: Download to Desktop Get started by downloading and unzipping the repository. Then, double-click the FundamentalsofProgramming.prj file inside MATLAB®.

Option 2: Open in MATLAB Online Log in to your MathWorks account to access your license. If you are associated with a university, use your university email to access a campus-wide license. The project will run automatically.

From there, you can follow the landing page instructions to get started with the examples. 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, if a loop is running longer than intended), click the Stop button in the RUN section of the Live Editor tab in the MATLAB Toolstrip.

Prerequisite Domain Knowledge

This module assumes familiarity with basic mathematics at a high school level. One exercise in programmingData.mlx requires the use of the quadratic formula, for instance. Understanding the chaos game requires locating points on a Cartesian coordinate system and understanding of either vectors or midpoints. Trigonometric functions are used as example functions. With respect to programming knowledge, this module is intended for absolute beginners who have used simple calculators in the past.


NavigationOverview.mlx This script brings together links and short descriptions of the content in the recommended order of use.

Introduction.mlx Open in MATLAB Online

This overview of the concepts of programming also includes discussion of errors, documentation, and other commonly encountered challenges for beginners.

Learning Goals:

  • Recognize and use the terms input and output
  • Recognize, interpret, and respond to messages about syntax errors
  • Recognize and interpret comments in code
  • Use documentation and search to learn more about how to use a programming language
  • Recognize and explain the importance of attention to detail when coding

Data.mlx Open in MATLAB Online

This script introduces double and string data types through interactive examples and exercises.

Learning Goals:

  • Recognize and explain that floating point arithmetic does not operate under the same rules as real number arithmetic
  • Apply the limitations of floating point arithmetic to computation
  • Recognize and use strings to store and communicate textual data
  • Recognize and use whitespace in string operations
  • Recognize and interpret special characters that are neither text nor numbers
  • Recognize and explain simple consequences of the interactions between data types

Arrays.mlx Open in MATLAB Online

This script introduces 1, 2, and 3-D arrays, as well as a brief overview of matrix operations. Applications include both text and image data.

Learning Goals:

  • Identify, create, and use vectors containing numbers or text
  • Apply vector indexing to extract information from a vector
  • Identify, create, and use matrices containing numbers or text
  • Apply matrix indexing to extract information from a matrix
  • Identify standard file types and the corresponding extensions
  • Explain why file type matters and import data from external files
  • Recognize and use three dimensional arrays

Branches.mlx Open in MATLAB Online

This script introduces the concept of conditional branching in the form of if/else branches and switch statements.

Learning Goals:

  • Recognize and apply if/then branching logic to solve problems
  • Recognize and apply switch branching logic to solve problems

Loops.mlx Open in MATLAB Online

This script introduces the concept of conditional looping in the form of for loops and while loops.

Learning Goals:

  • Use for loop logic and syntax to write and execute iterative code
  • Use while loop logic and syntax to write and execute repetitive code, and decide when it is the correct method

ChaosGameProject.mlx Open in MATLAB Online

Learning Goals:

  • Apply conditional branching and looping logic in context to solve problems
  • Explain that different programming solutions to the same problem can run in very different amounts of time
  • Identify common file formats and their extensions
  • Communicating results by exporting data from a program in a standard, shareable file format

Algorithms.mlx Open in MATLAB Online

Learning Goals:

  • Explain the concept of an algorithm
  • Implement an algorithm presented in pseudocode
  • Explain the importance of testing both code and algorithms

chaosGame.m This plain code file presents the basic scaffolding used to build an implementation of the chaos game on a square in programmingChaosGameProject.mlx.

CollectedProTips.mlx This live script serves as a collection of notes on using the Live Editor and the MATLAB language in the context of these scripts. All of this material is presented in the other scripts, but this one is used for reference.

Data Files

  • turkeys1.jpg is used in programmingIntroduction.mlx and programmingArrays.mlx
  • fileformats.mat is used in programmingChaosGameProject.mlx
  • EncryptedImage.mat is used in programmingAlgorithms.mlx
  • BW_Images.mat is used in programmingAlgorithms.mlx




The license for this module is available in the file in this GitHub repository.


The solutions are available upon instructor request. If you would like to request solutions or have a question, contact the MathWorks online teaching team.

Copyright 2021-2022 The MathWorks, Inc.

Cite As

Emma Smith Zbarsky (2023). Fundamentals-of-Programming (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2021b
Compatible with R2021a and later releases
Platform Compatibility
Windows macOS Linux
More Files in the  Distance Learning Community

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!


Version Published Release Notes

See release notes for this release on GitHub:


See release notes for this release on GitHub:


See release notes for this release on GitHub:


See release notes for this release on GitHub:


See release notes for this release on GitHub:


See release notes for this release on GitHub:


To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.