Unexpected behavior with From Workspace block in Simulink

1 次查看(过去 30 天)
The From Workspace block for Simulink is supposed to output data based on the time column in the variable. I have a model at a sample rate 5 times faster than the From Workspace, ie: 0.05 for Data, 0.001 for Model.
When I record the data from the From Workspace block at the Model sample rate of 0.001, I mostly see the data repeated 5 times but sometimes I see it repeated 6 times followed by 4 times for the next. This creates errors in my calculations because the expected data is wrong:
ie, 0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 2 <- extra "2" 3 3 3 3 too little "3" 4 4 4 4 4

采纳的回答

Kaustubha Govind
Kaustubha Govind 2013-5-29
(I presume you meant that 0.01 is your model's sample rate, because 0.05 is 50 times 0.001, not 5 times)
This looks like an floating-point/accuracy issue - 0.05*3 is slightly larger than 0.01*15:
>> format hex
>> 0.01*15
ans =
3fc3333333333333
>> 0.05*3
ans =
3fc3333333333334
Which is why, for the 15th sample, the previous data point (=2) is used.
Perhaps you can adjust the time column of the imported variable so that it is multiples of 0.01 instead of 0.05?
  2 个评论
Thomas Marullo
Thomas Marullo 2013-5-29
Sorry, you are indeed correct. From Workspace block is 0.005000000000000 and model sample rate is 1.000000000000000e-03. I think your recommendation of changing the From Workspace block to be multiples of the model sample rate is a good method.
Thomas Marullo
Thomas Marullo 2013-5-29
I also tried using 0.04 as my From Workspace timing and 0.01 as my model sample rate and I had the same problems at step 40. I didn't think there would be a problem using this case since,
>> 0.01*40
ans =
3fd999999999999a
>> 0.04*10
ans =
3fd999999999999a

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by