Illustration of variable scope, MATLAB in Engineering

Illustration of Variable scope:

Running this function does not add any of variables to the workspace, as elaborated:

>> clear

>> who

>> disp(mysum([5 9 1]))

   15

>> who

>> 

The variables that are also defined in the Command Window cannot be used in a function.

Though, scripts (as opposite to the functions) do interact with the variables which are defined in the Command Window. For illustration, the function is changed to be a script mysummfile.

731_Variable Scope1.png

 

Posted Date: 10/19/2012 8:59:32 AM | Location : United States







Related Discussions:- Illustration of variable scope, Assignment Help, Ask Question on Illustration of variable scope, Get Answer, Expert's Help, Illustration of variable scope Discussions

Write discussion on Illustration of variable scope
Your posts are moderated
Related Questions
Finding a sting - function findstr: The function findstr receives two strings as input arguments. It finds all the occurrences of shorter string contained by the longer, and r

Referring to and Showing Cell Array Elements and Attributes: Just as with the other vectors, we can refer to individual elements of the cell arrays. The only difference is tha

Reading from a Mat-File: The load function is used to read from various types of files. As with save function, by default the file will be supposed to be a MAT-file, and load

Solving 2 × 2 systems of equations: However this may be easy in a MATLAB, in normal finding solutions to the systems of equations is not. The systems which are 2 × 2 are, thou

Illustration of Sound files: For illustration, the following script generates a subplot which shows the signals from chirp and from train, which is as shown in figure:

Example Exit modular program: In the illustration below, the user  Chose the Limit; -   Whenever prompted for n, entered the two invalid values before finally ente

Defined a variable in work space: The variables defined in the script will become a part of the workspace: >> clear >> who >> mysummfile    15 >> who


Illustration of Variable scope: Running this function does not add any of variables to the workspace, as elaborated: >> clear >> who >> disp(mysum([5 9 1]))

Example of image processing: The other illustration generates a 5 × 5 matrix of arbitrary integers in the range from 1 to the number of colors; the resultant image is as shown