Azzera filtri
Azzera filtri

Calculation error?? system always gives output =[0 0 0 (value in index 3 - value in index 1) 0]

1 visualizzazione (ultimi 30 giorni)
I is defined in workspace and feed to the Matlab function from a constant block in Simulink. I is timeseries object : [0 1 2 3 4; 5 6 9 11 12] oldval is the previous step of arr using memory block in Simulink. so Oldval always catches the previous value of arr.
I managed to simulate system with incorrect result.
The output arr is expected to be =[10 11 13 15 16] but I got arr=[0 0 0 5 0] I tested with various I value, and I noticed that the system always gives arr =[0 0 0 (value in index 3 - value in index 1) 0] in this example, (value in index 3 - value in index 1 = 11 minus 6 = 5)
function arr= fcn(I,count,oldval)
persistent integ_signal if isempty( integ_signal) integ_signal=zeros(1,5) end persistent a if isempty(a) a=zeros(1) end
arr=zeros(1,5);
ii=zeros(1,5);
aa=zeros(2,5);
integ_signal=oldval;
%coder.extrinsic('load');
%aa=load('data.mat','I');
if count==1
a=1;
ii(a)=count;
integ_signal(1,ii(a)) = 10; % Initial Condition
end
if count ~= 1
a=count;
ii(a)=count;
integ_signal(1,ii(a))= integ_signal(1, ii(a)-1)+ I(2,ii(a))-I(2,ii(a)-1);
arr(1,ii(a)) = integ_signal(1,ii(a));
end
a = a + 1;
end

Risposte (0)

Categorie

Scopri di più su Simulink 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