Info

This question is closed. Reopen it to edit or answer.

How to use for loop in m-function in SIMULINK for Online tuning?

2 views (last 30 days)
Using m-function for online ILC iteration update (P-type Law), how can compute, store and update for the next cycle?
Note-Both equation are similar.
I am using ICL P-type update law (any above eq) where im calling a m-function which will take parameters into the .m file (function ILC) directly and feed it out into the PID controller. I am to iterate the whole CL system for at least 20 trials using the equation where
uk(t)/xdi'(t) is the input for the plant from the whole controller
ek(t)/ei(t+1) is the error
sum is stored in uk+1(t)/xd(i+1)(t)
L/Lambda= learning gain which can be constant of 0.04.
my codes in the ILC m-function are as follow:
function uk1 = ILC(uk,ek)
%#codegen
uk1=0
L=0.04
uk1=uk+L*ek;
uk1=uk
end
using the above codes, it works ok but i cannot confirm if the iteration is happening or no because no value is stored as array. OR do i need a for loop to iterate ILC?
function uk1 = ILC(uk,ek)
%#codegen
t=20
uk1=0
L=0.04
for n=1:1:t
uk1(n)=uk(n)+L*ek(n);
uk1=uk(n)
end
If i do the for loop,error of 'Attempted to access element 2. The valid range is 1-1.' ERROR yields. Please can you help me with the function codes also.
How should i implement the iteration, with or without the for loop?

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!