Clear Filters
Clear Filters

Using a slider Value to set a gain in simulink

3 views (last 30 days)
I'm using A slider from a GUI to set a parameter on a simulink model that it is controlling and I cant seem to input the data correctly for the gain. Can anyone explain to me why this is not happening.
**The simple code im using is:
% --- Executes on slider movement. function height_slider_Callback(hObject, eventdata, handles) % hObject handle to height_slider (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
z_position=get(handles.height_slider,'Value');
set_param('manualflight/flight_plan/zset', 'Gain', z_position);
set_param('manualflight','SimulationCommand','update')*
The error code that comes up is :
??? Error using ==> guimanualflight>height_slider_Callback at 96 Invalid setting in Gain block 'zset' for parameter 'Gain'.
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> guimanualflight at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)guimanualflight('height_slider_Callback',hObject,eventdata,guidata(hObject))
??? Error using ==> drawnow Error while evaluating uicontrol Callback
THanks

Accepted Answer

Paul
Paul on 27 Mar 2012
HAve solved it myself . For simunlink gain it requires a string value instead of a nuber value so adding the num2str comand will solve this problem:
z_position=get(handles.height_slider,'Value');
set_param('manualflight/flight_plan/zset', 'Gain', num2str(z_position));
set_param('manualflight','SimulationCommand','update')*

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!