×
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

Are Global Variables right for me?

Are Global Variables right for me?

Are Global Variables right for me?

(OP)
Hi,

I'm writing a rather large mass of code here with many many functions all need to use a struct filled with data.

What is the best way to access this struct from all the functions?

- As a Global variable.
- As a getappdata/setappdata to be attached to some main object.
- As the figure's 'UserData', to be accessed with get/set.


Thank you.
Y.

RE: Are Global Variables right for me?

Since you said "access" and I took that to mean read only, then why not the SW eng way and pass it each time as a formal parameter?  If a function needs to modify it, then you coudl return the struct or just the little piece you hanged and have your calling function insert it into the struct.  That way you have the option to make mex files on a case by case basis without restructuring your code.

RE: Are Global Variables right for me?

(OP)
Passing the parameter around won't be easy because it needs to be used from various functions that are called as button press callbacks. However, you gave me something to think about. I'll see how this can be adjusted. You're right that this will be the best way to do it.

Thank you.

Y.

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