/Fundamentals-of-Programming

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

Primary LanguageMATLABBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Fundamentals of Programming

View on File Exchange or Open in MATLAB Online

MATLAB Versions Tested

Curriculum Module

Created with R2023b. Compatible with R2023b and later releases.

Information

This curriculum module contains interactive MATLAB® 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.

Background

You can use these live scripts as demonstrations in lectures, class activities, or interactive assignments outside class. Fundamentals of Programming includes an introduction to programming which includes discussion of errors, documentation, and other commonly encountered challenges for beginners. Data introduces double and string data types. Arrays introduces 1, 2, and 3-D arrays, as well as a brief overview of matrix operations. Applications include both text and image data. Branches introduces the concept of conditional branching in the form of if/else branches and switch statements. Loops introduces the concept of conditional looping in the form of for loops and while loops. Chaos Game Project provides a scaffolded approach to implementing the chaos game by combining skills from each of the other scripts. The final script, Algorithms, introduces algorithms, pseudocode, and testing. Additional files include the navigation file Main Menu and the Collected Pro Tips.

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 mathematics at a high school level. One exercise in Data.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.

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 FundamentalsofProgramming.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. The imsplit command in Arrays.mlx is from the Image Processing Toolbox™.

Scripts

Introduction In this script, students will...
Earth-Moon-Rocket.png - 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 In this script, students will...
Fading-Pi.png - 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 In this script, students will...
Computer-Thoughtbubble.png - identify, create, and use vectors and matrices containing numbers or text.
- use vector indexing to extract information from a vector or 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 In this script, students will...
Maze.png - recognize and apply if/then branching logic to solve problems.
- recognize and apply switch branching logic to solve problems.

Loops In this script, students will...
SeasonLoopFinal.png - 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.

Project In this script, students will...
ChaosGameAngle.png ChaosGameSquare.png - 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.
- communicate results by exporting data from a program in a standard, shareable file format.

Algorithms In this script, students will...
Algo-flowchart.png - explain the concept of an algorithm.
- implement an algorithm presented in pseudocode.
- explain the importance of testing both code and algorithms.

Additional Scripts

Main Menu - Just the link sections of this script for navigation

Collected Pro Tips - Notes on how to implement particular concepts in MATLAB

License

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

Related Courseware Modules

Courseware Module Sample Content Available on:
Treasure Hunt Game: Learn to Code
Build and customize an interactive searching game
TreasureHuntAnimation.gif OpenInFX.pngOpenInMO.pngGitHub
Programming: Structuring Code
Learn how to organize your code into functions, debug, comment, and share
RGB-Turkeys.png OpenInFX.pngOpenInMO.pngGitHub
Programming: Organizing Data
Learn more about strings, numeric data types, memory, and ways of storing data
sst.png OpenInFX.pngOpenInMO.pngGitHub

Programming: A Starter Project Using MATLAB and Python
Use MATLAB, Python, and the OpenWeather API together to implement a weather prediction dashboard
TokyoWindMap.gif
OpenInFX.png
OpenInMO.png
GitHub

Or feel free to explore our other modular courseware content.

Educator Resources

How to 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.

© Copyright 2023 The MathWorks™, Inc