Programming: Structuring Code
Programming: Structuring Code
Curriculum Module
Created with R2021b. Compatible with R2021b and later releases.
Description
This curriculum module contains interactive live scripts that teach fundamental concepts and basic terminology related to programming computers. This module focuses on organizing code into functions, describing, debugging, and sharing code.
These scripts can be used as part of a lecture, as activities in an instructional setting, or as interactive assignments to be completed outside class.
##Get started with the Programming: Structuring Code interactive examples##
by downloading and unzipping the repository. Then, double-click the StructuringCode.prj file inside MATLAB®. 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 programming concepts such as floating point doubles and strings, structures including constants, vectors, matrices, and arrays, and control flows including if/else, for loops, and while loops, as well as how to use them in MATLAB. These ideas are all presented with interactive examples in Fundamentals of Programming.
Details
Organizing code into functions improves the readability, reusability, and ease of testing. This script addresses built-in functions, refactoring code to create functions, local functions, functions defined in their own files, programmatic scope and the MATLAB path, and how to pass functions as arguments to other functions.
Learning Goals: In this script, students will...
- use mathematical functions to use MATLAB as a calculator.
- use the documentation to locate functions and determine how to use them.
- write simple functions with inputs, outputs, and side effects, and ensure the functions are on your MATLAB path.
- pass functions as arguments by using function handles.
Everyone makes mistakes when coding or interacting with computer programs, but you can fix these mistakes. This script introduces the MATLAB Code Analyzer, errors, warnings, breakpoints, stepping, and other tools for minimizing errors as well as identifying and removing bugs from your programs.
Learning Goals: In this script, students will
- identify warning messages and locate and fix the problem.
- locate and fix syntax errors.
- recognize and isolate run-time errors.
Clearly documenting and communicating your thinking is essential to program with others or even your future self. This script addresses why and how you should document and comment your code.
Learning Goals: In this script, students will...
- write comments and documentation for a self-defined function.
- select meaningful variable names and add code and documentation to an existing function.
Writing code for yourself is the first step, but when you create something useful or interesting, you also need to know how to share your work with others. This script offers a brief introduction to sharing your code with others.
Learning Goals: In this script, students will...
- add scripts to a project.
- clone a GitHub repository.
- use the Compare tool to see differences between two versions of the same live script.
Related Courseware Modules
Products
MATLAB®
License
The license for this module is available in the License.md file in this GitHub repository.
Support
Have any questions or feedback? Contact the MathWorks online teaching team.
Copyright 2022 The MathWorks, Inc.
引用
Emma Smith Zbarsky (2023). Programming: Structuring Code (https://github.com/MathWorks-Teaching-Resources/Programming-Structuring-Code/releases/tag/v1.0.4), GitHub. 取得済み .
MATLAB リリースの互換性
プラットフォームの互換性
Windows macOS Linuxタグ
コミュニティ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!HelperFunctions
tests
HelperFunctions
バージョン | 公開済み | リリース ノート | |
---|---|---|---|
1.0.4.0 | See release notes for this release on GitHub: https://github.com/MathWorks-Teaching-Resources/Programming-Structuring-Code/releases/tag/v1.0.4 |
||
1.0.3 | See release notes for this release on GitHub: https://github.com/MathWorks-Teaching-Resources/Programming-Structuring-Code/releases/tag/v1.0.3 |
||
1.0.2 | See release notes for this release on GitHub: https://github.com/MathWorks-Teaching-Resources/Programming-Structuring-Code/releases/tag/v1.0.2 |
||
1.0.1 | See release notes for this release on GitHub: https://github.com/MathWorks-Teaching-Resources/Programming-Structuring-Code/releases/tag/v1.0.1 |
||
1.0.0 |