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
Initializing the data structure - Function: Function is shown as:   >> printcylvols(cyls) Cylinder x has a volume of 169.6 Cylinder a has a volume of 100.5

Image Processing: The Images are represented as grids, or matrices, of picture elements (known as pixels). In MATLAB an image usually is represented as a matrix in which each

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

Algorithm for subfunction: The algorithm for subfunction askforn is as shown:  Prompt the user for the positive integer n.  Loop to print an error message and reprom

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

Storing Strings in Cell Arrays: The one good application of a cell array is to store strings of various lengths. As cell arrays can store various types of values in the elemen

Write a program to examine exponential function: We will write a program to examine the value of e and the exponential function. It will be a menu-driven. The menu options wil

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 =

I have a 400x2 vel.dat and 20x2 xy.dat file, how can i plot a streamslice graph on matlab with this two files.

Program to Counting in a while loop: The script initializes variable counter to 0. Then, in the while loop action, each and every time the user successfully enter a number, th