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;
% Begin input: assistentie exoskeleton
u = zeros(1,5); %Begin met zero assistentie of je kan al een goede initiele guess maken eens je het systeem van het OpenSim model kent
max_it = 100; % Kwestie van niet te lang zoeken
lambda = 0.5; % Nu is dit nog een gewone constante, later verbeterd!
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,:)]; % Vervangen door Torque_driven model met u als input voor exoskeleton
e= [e ; r - y(k,:)]; %e(k+1,:)= r - (y0 + T.*u(k+1,:));
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)
Best Answer