Examples of MATLAB functions
Some very short, simple functions:
Calculates the square of a number.
Calculates the cube of a number.
Adds one to a number.
Checks to see if a number is "perfect".
Counts the number of odd numbers within a given range.
Functions showing input/output in MATLAB
Prints out numbers in a loop
Prompts user for a number, then echoes it.
Creates a file on disk and fills with input from the user.
Reads information from a file on disk, printing it to the screen.
Read data from a file with 4 columns, plots col 4 vs. col 2.
More complex functions, which check for valid input arguments:
Finds the smallest numerical value in a 1-D array.
Finds the largest numerical value in a 1-D array.
Finds and returns _both_ the smallest and largest numerical
values in a 1-D array.
Illustrates how a function can return more than one value.
A function which illustrates feval:
Calls a given function with a given single argument.
A function which illustrates strcmp:
Plays a guessing game with the user.
Example of how one can split a single big program into a main
loop plus subroutines
Calculate pi by successive approximations to
the area of a circle. No subroutines, all one
Same program, now with main loop and a single
subroutine (area_inside), all in one
source code file.
Main program only, requires external area_inside.m file