LECTURE_6_CS113_2010 - CS113 Introduction to Computing for...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS113 Introduction to Computing for Engineers MATLAB: Script and Function Files
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 MATLAB Script Files A MATLAB script file (Called an M-file) is a text (plain ASCII) file that contains one or more MATLAB commands and, optionally, comments. The file is saved with the extension ".m". When the filename (without the extension) is issued as a command in MATLAB, the file is opened, read, and the commands are executed as if input from the keyboard.
Background image of page 2
3 MATLAB Function Files A MATLAB function file (called an M-file) is a text (plain ASCII) file that contains a MATLAB function and, optionally, comments. The file is saved with the function name and the usual MATLAB script file extension, ".m". A MATLAB function may be called from the command line or from any other M-file.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 MATLAB Function Files When the function is called in MATLAB, the file is accessed, the function is executed, and control is returned to the MATLAB workspace. Since the function is not part of the MATLAB workspace, its variables and their values are not known after control is returned. Any values to be returned must be specified in the function syntax.
Background image of page 4
5 MATLAB Function Files The syntax for a MATLAB function definition is: function [val1, … , valn] = myfunc (arg1, … , argk) where val1 through valn are the specified returned values from the function and arg1 through argk are the values sent to the function. Since variables are local in MATLAB the function has its own memory locations for all of the variables and only the values (not their addresses) are passed between the MATLAB workspace and the function.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Three forms of the use of a function in Matlab are: >> VAR = function_name(arg1,arg2, …); >> [VAR1,VAR2,. ..] = function_name(arg1,arg2, …); >> function_name(arg1,arg2, …); A Matlab function like a mathematical function is a rule where given a certain input or inputs, the rule tells you how to compute the output value or how to produce an effect (e.g. the plot function produces a figure). The inputs are called the “arguments” to the function.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/29/2012 for the course CSC 113 taught by Professor Phillipregali during the Fall '10 term at Catholic University of America.

Page1 / 24

LECTURE_6_CS113_2010 - CS113 Introduction to Computing for...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online