フィルターのクリア

How to force a variable to a value in Simscape language?

1 回表示 (過去 30 日間)
Paolo
Paolo 2017 年 3 月 14 日
回答済み: Arnav Mendiratta 2017 年 3 月 20 日
Hello everybody,
I'm modeling a poppet valve.
The poppet position is described as follows:
v.der == 1/m * ( A.p*A1 - B.p*A2 - k*x0 - k * x - c* x.der);
x.der == v;
I have to set a limit to the poppet position x, kind of:
if x > Xmax
x == Xmax
end
I tried with a let-in with if-else enclosed, but it says I can't pass .der to if statement.
Does anybody have any idea?
Thanks
Paolo

回答 (1 件)

Arnav Mendiratta
Arnav Mendiratta 2017 年 3 月 20 日
As long as x.der and v.der are valid variables containing a scalar values or array, the '>' operator should work. With your code, it's hard to tell what all these variables are. This happens possibly because you are assigning a struct to x.der in this line:
x.der == v; % v is a stuct from previous line
And then, within your if-else, you are comparing a struct ('x') with a scalar value ('Xmax').
Instead of using if-else statement, a better approach is to use "assert" to test that all your variables are valid. Refer to the documentation here:

カテゴリ

Help Center および File ExchangeFoundation and Custom Domains についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by