MATLAB Answers

Precision Value fixing in Simulation using xlsread

2 views (last 30 days)
Shouvik  Das
Shouvik Das on 14 Aug 2012
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) = [1 1.5 2]
tc(1).input1.time = [0 0.025 0.050]
tc(1) = [10 20 30]
tc(1).input2.time = [0 0.025 0.050]
tc(n) = [5 5.5 6]
tc(n).input1.time = [0 0.025 0.050]
tc(n) = [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
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.
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:
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.

Community Treasure Hunt

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

Start Hunting!