×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Simple question!

Simple question!

Simple question!

(OP)
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!

RE: Simple question!

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

RE: Simple question!

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources