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.

Answers (1)

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 Comments

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' ?
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.
I think there could exist a bug in the derivative block, because when i rebuilt the derivate block on my own, this problem disappeared.

Sign in to comment.

Categories

Products

Release

R2018a

Asked:

on 25 Mar 2019

Commented:

on 26 Mar 2019

Community Treasure Hunt

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

Start Hunting!