Programming: Structuring Code

These live scripts teach programming basics related to organizing code into functions, describing, debugging, and sharing code.

ダウンロード: 86

更新 2023/1/27

GitHub から

GitHub でライセンスを表示

Programming: Structuring Code

View Programming: Organizing Data on File Exchange or Open in MATLAB Online

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

Functions.mlx Open in MATLAB Online

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.

Debugging.mlx Open in MATLAB Online

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.

CommentingCode.mlx Open in MATLAB Online

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.

SharingCode.mlx Open in MATLAB Online

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

  • Fundamentals of Programming on GitHub or View <File Exchange Title> on File Exchange
  • Programming: Organizing Data on GitHub or View <File Exchange Title> on File Exchange

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 リリースの互換性
作成: R2021b
R2021b 以降のリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
コミュニティ
 Distance Learning コミュニティのその他のファイル

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
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

この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。
この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。