Why is the method rto.InputPort(1).Data wrong?

Hi.
I am trying to get the value of Display block by m scripts. I am using the following scripts learned from Access Block Data During Simulation.
obj2=get_param([model_name,'/EngineRPM'],'RuntimeObject');
obj2.InputPort(1).dataasdouble
This method can return correct answer indeed, but sometimes the result is not correct:
Snipaste_2019-03-25_16-45-20.jpg
Why? And what should I do?
Thanks for your attention.

답변 (1개)

yang xiang
yang xiang 2019년 3월 26일

0 개 추천

Finally I found the where the problem is, however I still do not know what's the essantial reason.
Snipaste_2019-03-26_09-32-52.jpg
the display block "d3" shows right value in its UI, but when we try to get the value via code, it returns zero number.
this problem doesn't occur in other display blocks (and derivative blocks too), and even doesn't occur when I copy this block to other models:
Snipaste_2019-03-26_10-03-34.jpg
It really confused me. Could someone gives me some more information?

댓글 수: 3

Walter Roberson
Walter Roberson 2019년 3월 26일
편집: Walter Roberson 2019년 3월 26일
That would suggest to me that the block name is possibly not 'd3' . For example it might be 'd3 '
Or perhaps there is something else in the model that has a 'd3' ?
yang xiang
yang xiang 2019년 3월 26일
No. I add those display blocks just for debugging. There is no any other blocks named like that, if i made a typo in the ‘d3’ block, matlab should threw a error message rather that a zero number.
yang xiang
yang xiang 2019년 3월 26일
I think there could exist a bug in the derivative block, because when i rebuilt the derivate block on my own, this problem disappeared.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interactive Model Editing에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 3월 25일

댓글:

2019년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by