首页 文章

将simulink块转换为GUI代码?

提问于
浏览
1

我想在MATLAB中创建一个GUI,它有两个滑块,可用于调整值a和b . 我知道我可以让GUI打开simulink并使用simulink执行此操作,然后使用UDP对信息进行分组,如下图所示:

http://i.imgur.com/pkxomQi.png

但是,我希望能够将这些simulink块转换为GUI滑块中的代码 . 更具体地说,我对编码数据包输出块感兴趣,因此GUI按钮可以发送信息 . 有谁知道如何做到这一点?

1 回答

  • 1

    只要您知道块的"path",就可以使用set_paramget_param设置/获取其参数 . 在您的情况下,第一个常量块具有路径 'rtpacketio/Constant' - 即系统名称后跟 / ,后跟块的名称 .

    要找出可用于块的参数,您可以这样做,

    >> get_param('rtpacketio/Constant', 'DialogParameters')
    
    ans = 
    
             Value: [1x1 struct]    <<< This is the one you need to change
    VectorParams1D: [1x1 struct]
      SamplingMode: [1x1 struct]
            OutMin: [1x1 struct]
            OutMax: [1x1 struct]
    OutDataTypeStr: [1x1 struct]
         LockScale: [1x1 struct]
        SampleTime: [1x1 struct]
       FramePeriod: [1x1 struct]
    

    请注意,这些参数的值不是 struct s - 从 DialogParameters 参数返回的struct数组表示有关参数的信息;当你设置或获得一个块's parameter it must be a string (because it'进入 edit 控件时) . 在要设置此参数的代码中,您可以执行以下操作:

    set_param('rtpacketio/Constant', 'Value', num2str(myConstantValue));
    

    如果您需要高精度,您可能希望用更准确的等效替换 num2str .

相关问题