Precision Value fixing in Simulation using xlsread

조회 수: 1 (최근 30일)
Shouvik Das
Shouvik Das 2012년 8월 14일
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.

답변 (1개)

Ryan G
Ryan G 2012년 8월 14일
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
Shouvik Das
Shouvik Das 2012년 8월 15일
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 2012년 8월 15일
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?

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

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by