我有一个 Simulink 模型,其中包含 Check Static Range 块。在我的基础工作区中,我有一个名为 myNum=3
的变量。在 Check Static Range 块内,有一个名为“断言失败时的模拟回调”的编辑框。在此编辑框中,我编写了 disp(num2str(myNum))
。我期望的是在发生断言时看到命令窗口中显示的 myNum 值。 评估 Checks_SRange 块的 'AssertionFcn' 回调时出错...未定义的函数或变量 'myNum'。”
相反,当我使用 断言块,它工作没有问题。如何使 Check Static Range 块识别工作区中的变量?
I have a Simulink model with a Check Static Range block in it. In my base workspace I have a variable called myNum=3
. Inside the Check Static Range block, there is an edit box called 'Simulation callback when assertion fails'. In this edit box I wrote disp(num2str(myNum))
. What I expect is to see the value of myNum displayed in command window when an assertion occurs. Instead I get "Error evaluating 'AssertionFcn' callback of Checks_SRange block... Undefined function or variable 'myNum'."
When I tried the same callback with the Assertion block, it worked without problems. How can I make the Check Static Range block recognize my variables in workspace?
发布评论
评论(2)
检查静态范围块在掩码下方有一个断言块。 Simulink 回调字符串是在封装工作区而不是基础工作区中计算的,这就是您看到错误的原因。尝试这样做来强制在基础工作区中进行计算,
disp(num2str(evalin('base','myNum')))
The Check Static Range blocks have an Assertion block underneath a mask. The Simulink callback string is evaluated in the mask workspace, instead of the base workspace which is why you're seeing the error. Try this instead to force evaluation in the base workspace,
disp(num2str(evalin('base','myNum')))
我这里没有Matlab来测试。您是否在编辑框的内容周围加上了引号? 'disp(''3'')' 有效吗? (使用双单引号,因为您在字符串中)
I don't have a Matlab here to test. Did you put quotes around the content of the edit box ? Did 'disp(''3'')' works ? (with double single quotes since you're in a string)