Expected a value representable in the C type 'int'
Show older comments
I'm using MATLAB function blocks in Simulink. but there were some errors about data type. I can't understand the error messages. what made this error?
function xd = fcn(xdd,t)
t = t*10+1;
xd = xdd(t,1);
function xd = fcn(xdd,t)
t = t*10+1;
xd = xdd(t,1);


Answers (1)
Walter Roberson
on 4 Nov 2023
0 votes
You are taking whatever arrives in t and multiplying it by 10 and adding 1, and then you try to use that as an index into the zdd variable.
But the values into t are derived from the system clock -- and the system clock is not running at exact integer multiples of 1/10th second: it is running at about 0.025 seconds or so.
If you configured continuous time then remember that clock time may vary arbitrarily, being changed adapatively to meet integration tolerances.
If you configured discrete time then you needed to configure a larger step time -- and if you do use 1/10th of a second or integer multiples of that, then you should probably toss in a round(t) because the timer is not certain to run exactly at 1/10 because double precision cannot exactly represent 1/10 .
Categories
Find more on Matrix Indexing 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!