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
function imread: The function imread can read an image file, for illustration a JPEG (.jpg) file. The function reads color images into a 3-dimensional matrix. >> myimage1

Use of Nested if-else statements: By using the nested if-else to select from among the three possibilities, not all the conditions should be tested. In this situation, if x is


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

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

Reading from a Mat-File: The load function is used to read from various types of files. As with save function, by default the file will be supposed to be a MAT-file, and load

Replacement : Replace a row by adding it to (or subtract from it) a multiple of the other row. For a given row ri, this is written as   ri  - srj →  ri Note that when r


Illustration of anonymous functions: Dissimilar functions stored in the M-files, when no argument is passed to an anonymous function, the parentheses should still be in the fu

Technique to creating this structure: An alternative technique of creating this structure, that is not as efficient, includes using the dot operator to refer to fields in the