Skip to content
MathWorks

Self-Paced Online Courses

  • Self-Paced Content
  • MathWorks
  • MATLAB Help Center
  • Community
  • Learning
  • Get MATLAB MATLAB
  • Sign In
    • My Account
    • My Community Profile
    • Link License

    • Sign Out
  • Contact MathWorks Support
  • Visit mathworks.com
  • Online Courses
MathWorks MathWorks

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • (English)
  • (Deutsch)
  • (Français)
  • (简体中文)
  • (English)

You can also select a web site from the following list

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文
    • English
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

image for course The How and Why of Writing Functions

The How and Why of Writing Functions

Increase code modularity and flexibility by writing custom functions. Debug functions, set the MATLAB path, and understand function precedence to resolve ambiguity in command and function names.

Course modules

Course Overview

Get an overview of the course and the course example.

Lessons:
  • Course Overview
  • Learning Outcomes and Prerequisites

Create Functions

Create a local function from code you want to repeat.

Lessons:
  • Why Write Functions?
  • Convert Script Code to a Function
  • Complications of Repeated Code in Scripts
  • Modify Function Inputs and Outputs

Function Files

Write function files for use outside of your script.

Lessons:
  • Local Functions vs. Function Files
  • Write a Function in a Function File

Functions with Multiple Outputs

Create and call functions with multiple outputs.

Lessons:
  • Write a Function with Multiple Outputs

Workspaces

Examine base and function workspaces and learn how MATLAB keeps them separate.

Lessons:
  • Introduction to Workspaces
  • Function Workspaces
  • View Base and Function Workspaces
  • Access the Function Workspace to Troubleshoot a Function
  • Debug a Function

MATLAB Path and Calling Precedence

Learn how MATLAB handles name conflicts and finds user-defined functions.

Lessons:
  • MATLAB Path and Calling Precedence
  • Add Folders to the MATLAB Path
  • Calling Precedence
  • MATLAB Calling Precedence

Project

Practice what you have learned in the course.

Lessons:
  • Course Recap
  • Pyramid Numbers

Conclusion

Learn next steps and give feedback on the course.

Lessons:
  • Summary
  • Additional Resources
  • Survey

Format:Self-paced

Language:English

Language

  • Hands-on exercises with automated feedback
  • Access to MATLAB through your web browser
  • Shareable progress report and course certificate

MATLAB Desktop Tools and Troubleshooting Scripts

Get acquainted with MATLAB tools to help you work more efficiently in the environment.

  • Trust Center
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Application Status
  • Contact Us

© 1994-2025 The MathWorks, Inc.