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
I have a frequency response data. How do I convert that to state space? I am given a 6 row and 3 column data (steady state). How do i convert that to state space model?

Matrix definitions: As we know the matrix can be thought of as a table of values in which there are both rows and columns. The most common form of a matrix A (that is sometime

deblank function: The deblank function eliminates only trailing blanks from the string, not leading the blanks. The strtrim function will eliminate both the leading and traili

Application: Menu driven Modular Program Numerous longer, more involved programs which have interaction with the user are menu-driven, that means that the program prints a men

Forward elimination: In forward elimination, we want to obtain a 0 in the a 21 position. To accomplish this, we can alter the second line in the matrix by subtracting from it

Replacing a string - function strrep: The function strrep finds all the occurrences of a substring within the string, and substitutes them with a new substring. The order of a

Example of Plotting from a Function: For illustration, the function can be called as shown below:      >> y = [1:2:9].^3      y =     1  27  125  343  729

Execute a exponential function program: Running the script will take up the menu as shown in the figure: Then, what happens will totally depend on which button(s) the

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

Expanding a function: The expand function will multiply out terms, and factor will do the opposite: >> expand((x+2)*(x-1)) ans = x^2 x-2 >> factor(ans)