MATLAB: Do I see a discrepancy in the simulation results when I pass parameters using the -p option for the Rapid Simulation (RSim) target in Real-Time Workshop 6.1 (R14SP1)

precisionrapidrsimrsimgetrtprtpsimulationsimulink coder

I am using the RSim target. My model includes a Constant block that is set to 104. When I follow the steps below, there is a discrepancy in the simulation results when I use the -p option. Otherwise, this problem does not occur. For example, if you use RSIMGETRTP to change the Constant block value to 105 before constructing the rtP structure, the discrepancy does not occur.
Reproduction Steps:
Use rsim.tlc for the Real-Time Workshop system target file and repeat the process for Constant block values 104 and 105.
1. Load 'testdatafile.mat'.
load testdatafile.mat
2. Build rtPTrial.mdl.
3. Run rtPTrial for 300 timesteps and look at the ScopeData output.
4. Get the rtP structure using
rtP = rsimgetrtp('rtPTrial.mdl');
5. Save the rtP structure in a MAT-file.
save rtPmatfile rtP
6. Execute rtPTrial.exe with the -p option for 300 timesteps and save results in 'outmatfile.mat'.
!rtPTrial -p rtPmatfile.mat -tf 300 -o outmatfile.mat
7. Load 'outmatfile.mat'.
load outmatfile
8. Plot the scope data.
simplot(rt_ScopeData) %returns all zeros for 'Constant' block value of 104

Best Answer

This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
We have verified that there is a bug in Real-Time Workshop 6.1 (R14SP1) in the way that the RSim target loads the rtp structure from the RSIMGETRTP command.
To work around this issue, change your model to compare the difference of the Relational Operator block inputs to EPS by using '<=' instead of '==' in the Relational Operator blocks.