Results 1 to 6 of 6

Math Help - Global Variables Trouble.

  1. #1
    Newbie
    Joined
    Jun 2010
    Posts
    3

    Global Variables Trouble.

    Hey there.

    I'm using GUIDE in Matlab to create a slider, and am trying to store this variable as a global variable so that I can use it in simulink. Is there any way that I can do this? I have written an .m file that says

    Code:
     
    
     global sRT1
      
       sRT1 = sliderValue
    (Where sliderValue is already defined in the code before it.)

    But this doesnt seem to actually update the variable.

    If I manually define the variable in the matlab workspace eg "temperature1 = 34" then the variable shows in simulink as 34. If I run the GUIDE program I have written and move the slider around, the matlab workspace shows that "temperature1 = 45.6" (or whatever the slider value is). However, when I run the simulink program again, the value still shows as 34. (or the previously defined value that I have manually set in the MATLAB workspace).

    Sorry for the rather unorganised post, thanks for reading it.

    Does anybody have any idea why this is happening?

    EDIT:

    This might be an insight into why this is happening.



    Ignore the bottom 3 sliders, they for when I get the top one working.
    Last edited by Alexgdb; June 9th 2010 at 02:47 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    I think you have to make sliderValue a global variable in the workspace aswell as in your calling function before you can use it there.

    Ie type "global sliderValue" at the comand propmt before you start. I am not sure tho, I will look into it more tonight.

    Elbarto
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jun 2010
    Posts
    3
    You, my friend are a god. Just one last thing though.

    If I run the simulink model with a simulation stop time of "inf", I have to stop and restart the simulation for the new values to be used if I change the slider value. Is there any way to make the values of the slider 'live' so that the can be updated in the simulink model as I move them on the slider?

    Alex
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    I am glad that worked for you - I had a stab in the dark there so wasn't sure if it was good advice or just a plain lie

    As far as the simulink model is concerned, I am not familiar with how simulink works but I would assume it uses a handle structure for its objects (basically uses the same principle as matlab's figures/GUI's use) in which case it is possible to do what you want.

    Assuming the above is correct,

    1) you can pass in the handle to your simulink model into your GUI and store that as a variable using the "guidata" function.
    2) every time the slider changes value, you can change the simulink variable by using the "set" command since you will always know the handle to your model.

    The advantage of this approach is that it eliminates global variables altogether and is much more maintainable. If you post up your simulink model and your current code with an explanation of how to run it then I might be able to see if there is a way to implement this.

    I apologize I cant be more helpful at the moment, I have more of a civil engineering background so have not had any experience with simulink yet nor do I quite understand exactly what its applications are.


    Regards Elbarto
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Jun 2010
    Posts
    3
    Thanks, I will give that a try. Here is the Model:
    MEGAUPLOAD - The leading online storage and file delivery service

    Remember that you have to define the following global variables in the matlab workspace before the model will work.

    >> global sliderValue
    >> global sliderValue2
    >> global sliderValue3
    >> global sliderValue4
    >> global thermostatValue

    Alex
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    Unfortunately your model does not work in my matlab with the instructions you posted (I am running 2008b).

    Maybe this link might offer some assistance:

    Passing data between Simulink and MATLAB GUI
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: February 15th 2010, 03:43 AM
  2. global max an global min
    Posted in the Calculus Forum
    Replies: 1
    Last Post: December 3rd 2008, 03:45 PM
  3. Replies: 5
    Last Post: September 18th 2008, 10:11 PM
  4. Global max/min.
    Posted in the Calculus Forum
    Replies: 5
    Last Post: March 28th 2008, 01:43 PM
  5. trouble with change of variables
    Posted in the Calculus Forum
    Replies: 2
    Last Post: March 26th 2008, 06:16 PM

Search Tags


/mathhelpforum @mathhelpforum