Matlab_BlockInfoCheck

Change Block Value

最近做simulation发现,mdl_advisor竟然不检查enable port 和 action port的设置。
遂对比一下codegen,发现codegen也只对比出了action port的value区别。
Interesting. Happy 100th anniversary.

Common Command Conclusion

  1. find_system 查找simulink系统模型/模块/连线及注释;
  2. save_system 保存一个Simulink模型;
  3. add_block 在系统模型中加入指定模块
  4. delete_block 从系统模型中删除指定模块
  5. replace_block 替代系统模型中的指定模块
  6. close_system, bdclose 关闭一个simulink系统模型
  7. get_param 获取系统模型中的参数
  8. set_param 设置系统模型中的参数
  9. gcb 获得当前模块的路径名
  10. gcs 获得当前系统模型的路径名
  11. gcbh 获得当前模块的操作句柄
  12. bdroot 获得最上层系统模型的名称
  13. getSimulinkBlockHandle 从模块路径中获得模块句柄

Common Command Usage

// Check EnablePort 'StatesWhenEnabling' value
disp_all_val = 1;
blk = split(gcs, '/');
blk = blk{1};


%% Enable Block check.
bl = find_system(blk,'BlockType','EnablePort');  
for i = 1:length(bl)
    if ~strcmp(get_param(bl{i},'StatesWhenEnabling'), 'held')
        disp([get_param(bl{i},'StatesWhenEnabling') '    ' bl{i}]);
        set_param(bl{i},'StatesWhenEnabling','held')
        disp(['changed to:  ' get_param(bl{i},'StatesWhenEnabling')]);
    elseif disp_all_val
        disp([get_param(bl{i},'StatesWhenEnabling') '    ' bl{i}]);
    end
end


save_system(blk);
// GPD config check

disp_all_val = 1;

%% find model references
topmodel = split(gcs,'/');
topmodel = topmodel(1);

refs = find_system(topmodel, 'BlockType', 'ModelReference');

%% Since the coder loves i so much, there is no j or k.

for ii = 1:length(refs)
    open_system(refs{ii})
    sys_name = split(refs{ii},'/');
    sys_name = sys_name(end);
    
    blks = find_system(sys_name, 'BlockType', 'SubSystem');
    for i = 1:length(blks)
        hd = getSimulinkBlockHandle(blks(i));
        atts = get(hd);
        if isfield(atts,'CGPD_Object') && isfield(atts,'pd_sim_dsn')
            ori = get_param(blks{i}, 'CGPD_Object');
            an = ['mt_' lower(ori(8:end)) 'status'];
            if ~strcmp(get_param(blks{i},'pd_sim_dsn'), an)
                disp([get_param(blks{i}, 'CGPD_Object') '   ' get_param(blks{i}, 'pd_sim_dsn') '   ' blks{i}]);
                set_param(blks{i}, 'pd_sim_dsn', an);
                disp(['changed to: ' get_param(blks{i}, 'pd_sim_dsn')])
            elseif disp_all_val
                disp([get_param(blks{i}, 'CGPD_Object') '   ' get_param(blks{i}, 'pd_sim_dsn') '   ' blks{i}]);
            end
        end
    end
    
    
    
    save_system(sys_name)
    close_system(sys_name)
end


我是补充( ̄▽ ̄*)
get(gcbh), show current block details

我是吐槽(😭)
为毛不支持matlab啊啊啊啊啊。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值