Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel

Author: Rajesh Bhaskaran, Cornell University

Problem Specification
Step 1: Find Reactions RA, RB
Step 2: Calculate σx for ri = 1 cm
Step 3: Plot σx vs. ri
Step 4: Plot σx vs. ri: Take 2
Step 5: Plot σx vs. ri, Take 3: File Input/Output
Step 6: Plot σx vs. ri, Take 4: Functions
Tips

...

Plot σx vs. ri

...

 (Take 4: Functions)

Let's create a function to calculate the bending stress that outputs σx given (M, ri, ro ). Functions are really useful to break down your code into modules and also reuse parts of your code.

...


Add this to beam5.m. Run the file and check the output. You should get the same plot you got with beam3.m.

Subfunctions

Functions can be called from within a function. You can put multiple functions in one M-file as shown in the example located in this documentation page.

...

Your main_function file should look like this. 

Subfunction workspace

The last paragraph of the Local Functions documentation page says that "All functions, including local functions, have their own workspace that are separate from the base workspace.  Local functions cannot access variables used by other functions unless you pass them as arguments" and vice-versa. The following video covers this very important concept. 

...

In addition to this tutorial, there are several other references to use when learning Matlab. This link here will take you to Mathworks' video tutorials for Matlab.

Go to Tips

Go to all MATLAB Learning Modules