How do I write from a GUI button in a simulink parameter ?
5 views (last 30 days)
Show older comments
Hello I'm writing a GUI (without GUIDE) in order to control inputs in a simulink model (for example a command controlled by the user in the GUI, this command being an input in simulink model). Here is the code of the GUI:
function varargout = OHP_Fuel_Panel(varargin)
% MYGUI Brief description of GUI.
% Creation of matlab figure
ohp_h = figure('MenuBar','none','Name','OHP - Fuel Control Panel',...
'NumberTitle','off','Position',[360,500,450,285]);
% Construct the components
L_BP1_h = uicontrol(ohp_h,'Style','togglebutton','String','OFF','Value',0,...
'Position',[30 20 100 30],'callback',@change_label);
% Callbacks for MYGUI
function change_label(L_BP1_h,eventData)
pump_status = get(L_BP1_h,'Value');
if (pump_status==1)
set(L_BP1_h,'String','ON');
else
set(L_BP1_h,'String','OFF');
end
set_param('VSO/Left BP1 command','Value', pump_status);
end
end
The simulink model is made of a block constant 'Left BP1 command' for which the value is set to "pump_status" and this block is simpky sent to an output port. In the matlab command window, I launch the GUI by its file name, then I run the simulink simulation. But I got the following error message about the GUI:
??? Error using ==> OHP_Fuel_Panel>change_label at 40
Invalid setting in Constant block 'Left BP1 command' for parameter 'Value'.
??? Error while evaluating uicontrol Callback
and this message when I run the simulink model:
Error evaluating parameter 'Value' in 'VSO/Left BP1 command': Undefined function or variable 'pump_status'.
Could you help me to resolve this problem ?
0 Comments
Answers (1)
Sachin Ganjare
on 12 Sep 2012
Reason coould be uninitialized variable in workspace, instead of 'set_param' command use 'assignin' in your GUI code.
Hope this helps!!!!!!!!!
0 Comments
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!