matlab gui从模型里获取参数程序,如何在模拟过程中从GUI设置simulink模型参数?

我想在模拟该模型时在simulink块中设置增益(K值) .

61b7b921-5f14-404a-82cd-4a41325ebec6.png

我创建了一个包含按钮和编辑文本(标记为“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?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值