Programming: Structuring Code

버전 1.0.3 (973 KB) 작성자: Emma Smith Zbarsky
These live scripts teach programming basics related to organizing code into functions, describing, debugging, and sharing code.

다운로드 수: 30

업데이트 날짜: 2022/8/8

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 (2022). Programming: Structuring Code (https://github.com/MathWorks-Teaching-Resources/Programming-Structuring-Code/releases/tag/v1.0.3), 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!
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.