Effacer les filtres
Effacer les filtres

Using a slider Value to set a gain in simulink

3 vues (au cours des 30 derniers jours)
Paul
Paul le 27 Mar 2012
Commenté : DinhBa le 7 Juin 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

Réponse acceptée

Paul
Paul le 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')*
  1 commentaire
DinhBa
DinhBa le 7 Juin 2020
THank you very much. it helped me alot.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by