...
Panel |
---|
Author: Rajesh Bhaskaran, Cornell University Problem Specification |
...
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