Using a slider Value to set a gain in simulink

9 次查看(过去 30 天)
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')*

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by