필터 지우기
필터 지우기

Using a slider Value to set a gain in simulink

조회 수: 3 (최근 30일)
Paul
Paul 2012년 3월 27일
댓글: DinhBa 2020년 6월 7일
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

채택된 답변

Paul
Paul 2012년 3월 27일
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
DinhBa
DinhBa 2020년 6월 7일
THank you very much. it helped me alot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by