Skip to content

3. Creating Scripts in MatLab

Arduinerd edited this page May 24, 2018 · 4 revisions

It is possible to run multiline commands within the command window, however, it is more difficult to edit and less readable.

Creating a Script

Script Templates

  • Choosing function from the NEW button will create the template for a function in a new Editor window
    • Opening an Editor window will open the EDITOR, PUBLISH, and VIEW tabs in the ribbon

Pressing ALT+ENTER next to a squiggly line will apply the recommended fix

  • Choosing the example button from the NEW button will give a new file showing a title and two sections
  • Choosing class from the new button will open a new class definition

Discoverability and Path

  • In order to invoke a script you must be in the same file location
  • If you are not in the same folder, you must add it to the MatLab path
  • Trying to run the function from a different location (while it is open) will prompt you to set the path

Comparison and Search

  • Under the find files button, you can search for a file name, file text, or others
  • You can restrict your search in several ways
  • The comparison button allows for text comparison to see where text is added or deleted
  • You can save the result as an html file

Debugging

  • Breakpoints pause the program at a particular point
  • Breakpoints can be set by clicking the line number, selecting the menu item, or pressing F12
  • Within the EDITOR tab you can control execution after hitting a breakpoint

Publishing Scripts

  • By creating comments within sections, you can creates paragraph text that will appear upon pressing the publish button in the PUBLISH tab
  • You can format the text in several ways to appear as a html file
  • After adding code, both the code and the result will be visible after publishing
  • You can add LaTex formulas in the middle of a paragraph

Using LaTex

  • Within the Symbolic Toolbox is the MuPAD notebook which helps write LaTex
  • The app allows your to copy the input as LaTex code
  • syms x calls the Symbolic toolbox
  • latex(“function”) will print out the LaTex code for a function from the command line
  • LYX is a program which will achieve the same effect

LaTex is documentation preparation system which allows users to input mathematical formulas as plain text. It is preferred by most of the academic world for papers and other official documents.

Control Statements

Conditionals

Loops

Functions

  • functions require input and output arguments
    function [out1, out2] = functionName (in1, in2,…)

Objects and Classes

Clone this wiki locally