Simulink: How can I throw errors with the initialization commands in a masked subsystem?

Hello! I would like to evaluate parameters of a masked subsystem within the initialization code. The mask is created with the mask editor. The initialization code calls a m-function and passes the parameters of the block to this function. If e.g. the mass is negative, I wanto to display an error in the matlab command window.
if mass<0
error('mass is negative!')
end
If I use this code at the beginning of my initialization code, no error is displayed and the block doesn't initializes properly.
Does anyone know a solution? Thanks!

1 件のコメント

Kaustubha Govind
Kaustubha Govind 2012 年 10 月 25 日
Why not use the parameter callback function instead? That is probably the right place to validate parameters anyway.

サインインしてコメントする。

 採用された回答

Martin
Martin 2012 年 10 月 26 日
@Jeremy: It doesn't seem to work either...
@Kaustubha Govind:
I already tried to evaluate the parameters with the parameter callback function. The Dialog Callback calls an m-function:
hidden_block_cb(gcb,get_param(gcb, 'm'))
This seems to work if I type e.g. 5 in the block dialog box.But I would like to save the parameter mass=5 in the matlab workspace and then type 'mass' in the block dialog box. But then I get an error:
Error due to multiple causes ->Undefined function or variable 'mass' ->Error evaluating 'MaskCallback' of ... Undefined function or variable 'mass'.
I think to problem is that the get_param. But
hidden_block_cb(gcb,m)
doens't work either.
???

2 件のコメント

Does this work:
hidden_block_cb(gcb,str2num(get_param(gcb, 'm')))
Martin
Martin 2012 年 11 月 7 日
This worked out! Thanks a lot :)

サインインしてコメントする。

その他の回答 (2 件)

Jeremy
Jeremy 2012 年 10 月 25 日

0 投票

Perhaps the error is being thrown too low? Try throwAsCaller, and see if that works.
Carlos
Carlos 2014 年 9 月 18 日

0 投票

Hi,
I am having a similar issue, and I do not understand the proposed solution of using hidden_block_cb.
From the mask initialization tab I am trying to check the value of a variable. If loc == 999 I want to raise a warning. i.e. I want a warning to be shown in the Matlab command line. But using warning('message') or error('message') does nothing. Any ideas on how to do this? Thanks!

カテゴリ

ヘルプ センター および File Exchange で Simulink Functions についてさらに検索

製品

質問済み:

2012 年 10 月 25 日

回答済み:

2014 年 9 月 18 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by