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

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?

Example of Interpolation and extrapolation: The MATLAB has a function to do this, known as polyfit. The function polyfit finds the coefficients of the polynomial of the partic

Illustration of Gauss elimination: For illustration, for a 2 × 2 system, an augmented matrix be: Then, the EROs is applied to obtain the augmented matrix into an upper

Evaluating a string: The function eval is used to compute a string as a function. For illustration, below is the string 'plot(x)'is interpreted to be a call to plot the functi

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

Use polyval to evaluate the derivative at xder. This will be the % slope of the tangent line, "a" (general form of a line: y = ax + b). % 4. Calculate the intercept, b, of t

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

Vectors of Structures: In numerous applications, involving database applications, information generally would be stored in the vector of structures, instead of in individual s

Splits a string : The strtok function splits a string into pieces; it can be called in many ways. The function receives one string as an input argument. It appears for the fir