我想在模拟该模型时在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值 . 在模拟过程中,如果按下按钮,基本工作空间中的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?