Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MATLAB: How to get variables from GUI into Simulink

  • 25-11-2010 11:44AM
    #1
    Registered Users, Registered Users 2 Posts: 61 ✭✭


    Hey guys, I dont know if I'm wording my problem right but I have created a GUI, an m-file and a simulink. Initially I had the variables going from the m-file into the Simulink, but now I want the user to be able to change the variables so I have created a GUI. I keep getting an error though, I dont think the variables are going from the GUI m-file to the simulink model anymore. I remember you had to set something to do it, like simset or setcurrentsim or something but I cannot remember, so I was wondering can anyone help me with this one?



    The following is the error code being created:

    ??? Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error due to multiple causes.

    Error in ==> gui_mainfcn at 96
    feval(varargin{:});

    Error in ==> GUIForProject at 42
    gui_mainfcn(gui_State, varargin{:});

    Error in ==> @(hObject,eventdata)GUIForProject('pushbutton1_Callback',hObject,eventdata,guidata(hObject))


    Caused by:
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Value' in 'BusAssignment/Constant': Undefined function or variable 'X'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain1': Undefined function or variable 'kf'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain10': Undefined function or variable 'lf'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain11': Undefined function or variable 'kf'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain12': Undefined function or variable 'lf'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain13': Undefined function or variable 'lr'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain14': Undefined function or variable 'md'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain15': Undefined function or variable 'ma'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain16': Undefined function or variable 'lf'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain2': Undefined function or variable 'kr'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain3': Undefined function or variable 'kr'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain4': Undefined function or variable 'lr'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain5': Undefined function or variable 'm'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain6': Undefined function or variable 'igg'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain7': Undefined function or variable 'kf'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain8': Undefined function or variable 'kr'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Gain' in 'BusAssignment/Gain9': Undefined function or variable 'lr'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'DelayTime' in 'BusAssignment/Phase Delay': Undefined function or variable 'phi'.
    Error using ==> GUIForProject>pushbutton1_Callback at 140
    Error evaluating parameter 'Frequency' in 'BusAssignment/Sine Wave': Undefined function or variable 'w'.

    ??? Error while evaluating uicontrol Callback


Comments

  • Moderators, Arts Moderators Posts: 10,588 Mod ✭✭✭✭5uspect


    You may simply have to assign the variables needed by Simulink to the base workspace.
    assignin('base','var1',var1)
    

    Was the original m-file a function? If not then simulink sees the variables since they're stored in base by default. Making your code a function stores the variable in a workspace seen only by that function. If your simulink runs from the same functon, as a subfunction say, then you may only need to make those variables global.


  • Registered Users, Registered Users 2 Posts: 61 ✭✭[DM]Frink


    Yeah that worked, cheers!!!

    Stupid Matlab help....doesnt tell ya anything


  • Moderators, Arts Moderators Posts: 10,588 Mod ✭✭✭✭5uspect


    [DM]Frink wrote: »
    Yeah that worked, cheers!!!

    Stupid Matlab help....doesnt tell ya anything

    Matlab's help is fecking great TBH. I'm currently learning Fortran and pining for documentation as good.


Advertisement