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
Reduced Row Echelon Form: The Gauss Jordan technique results in a diagonal form; for illustration, for a 3 × 3 system: The Reduced Row Echelon Forms take this one step


Example of modular program: In a modular program, there would be one main script which calls three separate functions to complete these tasks: A function to prompt an us

Indexing into Vectors of structures: Frequently, when the data structure is a vector of structures, it is essential to iterate through the vector in order by various fields. F


Displaying expressions: The good-looking function will show such expressions by using exponents; for illustration, >> b = sym('x^2') b = x^2 >> pretty(b)

i want to run 4 instances of my matlab code on 4 processor cores. im executing the job from head node. i created a parallel job and assigned number of workers. but i don''t get bac

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

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

Plotting from a Function: The following function creates a Figure Window as shown in figure, which shows various types of plots for similar y vector. The vector is passed as a