Azzera filtri
Azzera filtri

Expected a value representable in the C type 'int'

11 visualizzazioni (ultimi 30 giorni)
榆信
榆信 il 4 Nov 2023
Risposto: Walter Roberson il 4 Nov 2023
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);

Risposte (1)

Walter Roberson
Walter Roberson il 4 Nov 2023
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 .

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by