1
當模型模擬時,我想在simulink塊中設置增益(K值)。如何在仿真過程中從GUI設置simulink模型參數?
我創建了一個GUI包含一個按鈕和編輯文本(標記的「text_box」),並且該按鈕的回調函數將設置在底座的工作空間指定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通過
% --- 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);
改變K的SIMULINK也試過,但我會得到錯誤說:
Error using robotics_gui_2>FK_button_Callback (line 429)
Invalid setting in Gain block 'Gain' for parameter 'Gain'
我能做些什麼來改變K的SIMULINK在模擬?