How can we define a variable in 'Matlab function' simulink block working on real time for storing the current status of any array and later enable us to use it?

2 views (last 30 days)
Consider this code and also 't' is the digital clock time sampled at 20kHz to make a simulation a real time while Tsw=1e-3 sec, if rem(t,Tsw)==0 tvec = [T0 T1 T2 T0 T0 T2 T1 T0]; tvec = cumsum(tvec); plot(t,tvec) hold all end the idea is that for t=0, this loop executes and define/calculate the tvec vector but for the next 19 iterations since the condition will not fulfilled and the loop will not execute, tvec is required to be same as it was calculated at t=0. Similarly, at t=1e-3 s or 21st sample, loop will be executed and tvec will be updated according to values of T0,T1,T2 at that instant. The problem occurs when I define tvec= zeros(m,n) and try to have the same 'tvec' as at t=0, for the next 19 samples. Because at every iteration, this statement executes and all values in tvec vanishes. I hope I have better communicate the problem facing.

Answers (0)

Categories

Find more on Simulink 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!