Value of variable after passing one simulation cycle
显示 更早的评论
Hi guys,
I have a pretty straightforward question I believe. Say i am applying a code using a MATLAB function block into my Simulink. I have a code which looks like this. If i run this code, will my D be reset to 0 every simulation cycle when it runs the code again from the beginning? Or my D output will remain as what I have set from the If statements shown. Same question goes for N. I plan to set N as some sort of delay in the form of a 'counter' to ensure that each of the D values I set will be fed into my simulation because at this point (my hypothesis), my prev codes give only one duty cycle probably because the code ran too fast? Dont really know the concept of simulation cycle between MATLAB function blocks with Simulink.
function D = BAT(P)
%% declare all variables %%
DPold = [0.2;0.4;0.6;0.8];
D = 0;
N = 0;
if N==0
D = DPold(1);
end
if N==1000
Pold(1) = P;
end
if N==1001
D = DPold(2);
end
if N==2000
Pold(2) = P;
end
if N==2001
D = DPold(3);
end
if N==3000
Pold(3) = P;
end
if N==3001
D = DPold(4);
end
if N==4000
Pold(4) = P;
end
N = N+1;
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!