【发布时间】:2013-06-04 11:31:54
【问题描述】:
我想在这个模型仿真时在simulink块中设置增益(K的值)。
我创建了一个包含一个按钮和一个编辑文本(标记为“text_box”)的GUI,该按钮的回调函数将通过指定基础工作空间中的K来设置增益。
% --- Executes on button press in FK_button.
function FK_button_Callback(hObject, eventdata, handles)
% hObject handle to FK_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global K;
text=get(handles.text_box, 'String');
value = str2double(text);
K = value;
但是,当我开始仿真时,simulink 模块只读取工作空间中 K 的值。在仿真过程中,如果我按下按钮,base work space中的K值会变为我设置的值,但simulink中的K值不会改变。
我也尝试使用 set_param API 来更改 simulink 中的 K
% --- Executes on button press in FK_button.
function FK_button_Callback(hObject, eventdata, handles)
% hObject handle to FK_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global K;
text=get(handles.text_box, 'String');
value = str2double(text);
%gui_variable is the model file name
set_param('gui_variable/Gain','Gain', value);
但我会收到错误提示:
Error using robotics_gui_2>FK_button_Callback (line 429)
Invalid setting in Gain block 'Gain' for parameter 'Gain'
在仿真过程中如何更改 simulink 中的 K?
【问题讨论】: