Hello,
I am writing an iterative algorithm that updates a vector "u" each iteration step. I also keep the previous vectors u, so I can control what happened previously, so each iteration there is a new row added to u. This row is the latest vector u if you want. So each iteration I try to update the latest u(k,:) I have by a new u(k+1,:).
The problem is not this iteration, but in each iteration step I find the new u(k+1,:) by minimizing a function "fun". However, this gives an error: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"
x0 = u(k,:);
fun = @(x)(r - (y0 + T.*x)).^2 + x-u(k,:);
u(k+1,:) = fminsearch(fun, x0);
Here is the full code: %% ILC algoritme clear all; close all; clc;
u = zeros(1,5);
max_it = 100;
lambda = 0.5;
y0 = [1 0 -1 3 4];
y= [];
r = 5* ones(1,5);
e = [];
Norm = [];
T= [1 5 3 4 5];
for k = 1:1:max_it
y = [y ; y0 + T.*u(k,:)];
e= [e ; r - y(k,:)];
Norm = [ Norm ; norm(e(k,:))];
if Norm(k) < 0.1
break
end
x0 = u(k,:);
fun = @(x)(r - (y0 + T.*x)).^2 + x-u(k,:);
u(k+1,:) = fminsearch(fun, x0);
end
figure
xlabel('Time_samples')
ylabel('Norm error')
title('Norm error in time')
plot(Norm)