Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple question!

Status
Not open for further replies.

TheJagg

Civil/Environmental
Apr 14, 2005
1
This is probably a simple question.

When i define a new variable, how do I make it constant?
How do I protect it from being changed later on?

Help appreciated!
 
Replies continue below

Recommended for you

use an .m file
inside this file write x=2;
so now x=2
when you use x inside the m file it is autmatically has the same value
so if you write y=2x so y=4 is displayed
so i think the answer of your question is to use m file not the command window of matlab because in command window every time you enter you need to write your variable
 
That doesn't work, since you could write x=3; later on and x would, not too surprisingly, become 3

If x was a constant then you wouldn't be able to write x=3 without an error message.



Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor