MATLAB Examples:

The table below points to a number of example MATLAB scripts.  Some (e.g., shippingCosts.m, stats.m) are complete programs and reasonable examples of appropriate documentation standards.  Others (e.g., mixedTextString.m) are program snippets.  These snippets demonstrate one simple technique.  They are not intended to be examples of complete documentation.  

Script

Function

Programming Feature Demonstrated

helloWorld.m demonstrate the MATLAB is alive disp()
fprintfDemo.m simple user dialog  read and print using fprintf()
mixedTextString.m  print and label numeric results mixing 'text' with num2str()
piston.m  compute the linear position of a piston as a function of crankshaft angle a complete example program - small, simple, and to the point
antenna.m  compute and graph the gain of a microwave antenna basic polar plot
shippingCost.m   compute shipping cost based on package weight selection structures - if statement
sum_1.m  computes the sum of 5 values repetition structure - for loop
sum_2.m computes the sum of "n" values repetition structure - for loop
whileDataFailToRead demonstrates a useful approach to reading and storing an unknown quantity of data - and an similar approach that fails repetition structure - while loop
 - while (more data), read 
 - unexplained 'glitch'
average.m  computes the average of "n" values by reading until eof repetition structure - while loop
while (more data), read and process
stats.m
testStats.m
function computes mean and standard deviation of array argument function - argument validity check - multiple (optional) output arguments
Roots of Equations
bulletcantileverGraph.m
bulletcantileverLinear.m
These scripts demonstrate techniques used to determine the roots of an equation.
bulletGraphical Approach
bulletLinear Search
The use of selection and repetition structures to ... finally ... address a real engineering problem that has no analytic solution.
Matlab Debugger:
bullet cantileverBinaryDebug.m
bullet binarySearchFlowchart
This script is useful to demonstrate the use of BREAKPOINTS  
Data Readers:
bulletdataReader1.m
bulletdataReader2.m
bulletdataReader3.m

Data Files:

bulletdata.txt
bulletfred.dat
These scripts demonstrate techniques used to read data from external data files. The use of textread() each script is a bit more useful than the previous one - dataReader3 is a very useful code sequence. 
Data Makers:
bulletlinearDataMaker
bulletarrayDataMaker
These scripts demonstrate techniques used to generate test data and write those data to external data files. The "C" language file i/o commands including fopen, fclose, & fprintf.
Caution - these scripts are under development and not complete - nevertheless, you may find them useful.
Absolute Value
bulletmagnitude.m
bulletmagnitudeTest.m
Compute the absolute value MATLAB Functions
bulleta simple function
bulleta testing script
simultaneousEquations.m Solve a set of three linear equations "left divide" and matrix inversion

Page updated October 24, 2002 04:44 PM