Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MATLAB: How to get variables from GUI into Simulink

  • 25-11-2010 10: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,520 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,520 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