Defined a variable in work space, MATLAB in Engineering

Defined a variable in work space:

The variables defined in the script will become a part of the workspace:

>> clear

>> who

>> mysummfile

   15

>> who

Your variables are:

i runsum vec

The Variables which are defined in the Command Window can be used in the script, but cannot be used in a function. For illustration, the vector vec could be defined in the Command Window (rather than in the script), but used in the script:

2145_Defined a variable in work space.png

>> clear

>> vec = 1:7;

>> who

Your variables are:

vec

>> mysummfileii

>> who

Your variables are:

i runsum vec

>> runsum

runsum =

   28

 

This, though, is very bad programming style. It is much better to pass the vector vec to the function.

 

It is possible, in a MATLAB and also in other languages, to have global variables which can be shared by functions. Though there are similar cases in which using global variables is efficient, it is normally regarded as the poor programming style.

Posted Date: 10/19/2012 9:01:51 AM | Location : United States







Related Discussions:- Defined a variable in work space, Assignment Help, Ask Question on Defined a variable in work space, Get Answer, Expert's Help, Defined a variable in work space Discussions

Write discussion on Defined a variable in work space
Your posts are moderated
Related Questions
Polyhedron - graphics objects: The field polyhedron.vertices is a matrix in which each row presents (x,y,z) points. The field polyhedron.faces defines the faces: for illustrat

Function used in binary search: The function below implements this binary search algorithm. It receives two arguments: the sorted vector and a key (on the other hand, the func

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

FOR Loop: The for loop, or the for statement, is used whenever it is essential to repeat statement(s) in the script or function, and whenever it is known ahead of time how man

Illustration of Matrix solutions: For illustration, consider the three equations below with 3unknowns x 1 ,x 2 , and x 3 : We can write this in the form Ax = b here A

Program of passing arguments to functions: This was an illustration of a function which did not receive any input arguments nor did it return any output arguments; it easily a

IS Functions for Strings: There are many functions for strings, that return logical true or false. The function isletter returns the logical true when the character is a lette

Individual structure variable: The individual structure variable for one software package may look like this: The name of the structure variable is a package; it has f

ischar function: The ischar function return the logical true if an array is a character array, or logical false if not. >> vec = 'EK127'; >> ischar(vec) ans =

Examine exponential function: The algorithm for the main script program is shown below:  Call a function eoption to show the menu and return the user's choice.  Loop