Filter löschen
Filter löschen

Using a slider Value to set a gain in simulink

3 Ansichten (letzte 30 Tage)
Paul
Paul am 27 Mär. 2012
Kommentiert: DinhBa am 7 Jun. 2020
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

Akzeptierte Antwort

Paul
Paul am 27 Mär. 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')*

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by