Precision Value fixing in Simulation using xlsread

1 view (last 30 days)
I work with set of Simulink/Stateflow models. I create a time and data structure for with the simulation values to be used in form of an array. I use 'sim' to start simulation. The second argument is the structure of timespan array and fourth parameter used is the data array
e.g. in a Simulation Frames -1 to N I have a structure like
tc(1).input1.data = [1 1.5 2]
tc(1).input1.time = [0 0.025 0.050]
tc(1).input2.data = [10 20 30]
tc(1).input2.time = [0 0.025 0.050]
...
...
tc(n).input1.data = [5 5.5 6]
tc(n).input1.time = [0 0.025 0.050]
tc(n).input2.data = [2 2 3]
tc(n).input2.time = [0 0.025 0.050]
this is used for creating fourth external input to 'sim'
For ease of dynamically setting the inputs through an excel interface so that the 'tct' structure is dynamically formed I use xlsread function to read from the input excel. What happens is the floating point representations are truncated to %*.4f format. I am able to see the full representation using
sprintf('%10.12f',value)
but I am not able to use this precise value for simulation. I enabled format long but that does not help. The Simulation outputs are still in *.4f format only.
For calculation intesive steps I am seeing remarkable difference in the output. I want simulate the whole model in Single Precision by taking all real inputs and outputs as *.12f format. My requirements need me to have a tolerance specification as +/-0.0005 so I am observing failures in the resulting output values.
Kindly help.

Answers (1)

Ryan G
Ryan G on 14 Aug 2012
Format long will not change the value but simply change the value that is displayed. The tolerance you describe should be relatively trivial to achieve and MATLAB should not round the data when you do the xlsread.
You could be running into this issue. This happens when the time in the simulation does not match the time input exactly.
The easy way to troubleshoot this issue would be to log the data directly from the inport you use to input the data in Simulink and compare that with the data input.
  2 Comments
Shouvik Das
Shouvik Das on 15 Aug 2012
Actually we have made an one-to-one mapping for inputs with the simulation timing since we create a simulation inputs in form of a structure of time and data array. I have even confirmd this by debugging the simulation.
In my model I have very calculation intensive steps like Cubic Equation whose values are formed cascaded operations. We are definitely in a situation of precision losses but I am able to achieve a tolerance of about +/-0.003 instead of +/-0.0005.
Ryan G
Ryan G on 15 Aug 2012
Perhaps you could copy/paste some numbers, with full precision, that you are actually using. The example you gave is simple so and I still stick by saying that +/- 0.0005 should be easy to achieve with single precision numbers. You can check the tolerance of single precision with:
eps(single(0))
However, there could be something going on with xlsread. You mention that you did the one-to-one mapping. Did this give you expected results? If not what were the differences?

Sign in to comment.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!