Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions (subprograms)

Similar presentations


Presentation on theme: "Functions (subprograms)"— Presentation transcript:

1 Functions (subprograms)
Built-in functions (sin, cos, ln, etc.) User-defined functions Sin (3.14) (argument) Function name

2 User-defined functions
Created as a .m file 1st line is function definition line function [output variables] = function_name(input variables) function_name same as filename Function is called from main script by [output variables] = function_name(input variables)

3 Local vs Global Variables
Local variables Only recognized within function file Can reuse the same variable names in another function file Global variables Name (and values) recognized globally (in all files involved) Need to be declared as global in all files involved global a x q

4 Data files Data from lab instrumentation
Saved in ASCII as pv_data.m (any extension except .mat) Data as numbers in columns and rows separated by space Using your favorite text editor Change any other delimiters (comma, colon) to space Remove any headers Load into Matlab by load pv_data.m Data is now available as variable(array) pv_data

5 Exporting data files Exporting an array A in Matlab session
>>save my_results.txt A -ASCII To use other delimiters >>dlmwrite('my_results.txt',A,';' ) Default delimiter comma Space as delimiter by ' ' No delimiter by ''


Download ppt "Functions (subprograms)"

Similar presentations


Ads by Google