- The line "time(it)=time(it-1)+dt;" inside the loop is unnecessary because you've already defined your "time" array using "time=0:dt:T;".
- The line "ref_old=pow_point(1);" and the subsequent use of "ref_old" inside the loop are unnecessary since you're already handling the assignment of "ref(it)" within the loop.
- When two consecutive "pow_point" values are the same, there's no need for interpolation, and we can assign the value directly to the entire interval between the two consecutive "time_point" corresponding to the same "power_point".
- The final loop that sets "setpoint=yref(s);" doesn't seem to serve a purpose in the context of generating the "ref" sequence, as "setpoint" is overwritten at every iteration and not used elsewhere.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1647856/image.png)