Input arguments to function include colon operator. To input the colon character, use ':' instead

Hello
I have four problems
The first is that I wrote these codes based on HATL MATLAB to predict the prediction. I do not know whether I wrote the correct functions or not.The second thing I wrote makes this mistake?
#####
I used this for coding
%%%%%%%%%%%%%%%%
Nonlinear system code is discrete:
%%
function x1=exocstrstateFcnCT1(x1,u1,p)
for i=1:p
x1=x1(i,:);
u1(1)=u1(i,1);
u1(2)=u1(i,1);
x1(i+1,:)=[0.9*cos(x1(3)) 0;0.9*sin(x1(3)) 0;0 0.9]*[u1(1);u1(2)]+[x1(1);x1(2);x1(3)];
end
end
%% CostFunction
function J1=myCostFunction1(x1,x1d,u1,x4had,data,x2had)
for i=1:p
u1=u1(i,:);
x1=x1(i,:);
x2had=x2had(2:p+1,:);
x4had=x4had(2:p+1,:);
J1=0.1*norm(x1-x1d,2)+0.2*norm(u1,2)+ 0.1*norm(x4had-x1-x14d,2)+0.1.*norm(x2had-x1-x12d,2);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nx=3;
ny=3;
nu=2;
nlobj1 = nlmpc(nx,ny,nu);
Ts = 0.1;
nlobj1.Ts = Ts;
p=6;
c=3;
nlobj1.PredictionHorizon = p;
nlobj1.ControlHorizon = c;
x1(1,:) = [0.5;0.6;0.7];
x1had=x1(1,:);
u1(:,1) = 0.2*[1;1];
validateFcns(nlobj1,x1,u1,[],{Ts});
%%%%%
nloptions1 = nlmpcmoveopt;
nloptions1.Parameters = {Ts};
%%
xHistory1 = x1(1,:);
Duration = 20;
lastMV1 = u1';
uHistory1 = lastMV1;
%%
for k = 1:(Duration/Ts)
t = linspace(k*Ts, (k+p-1)*Ts,p);
% Compute the control moves with reference previewing.
x1k = xHistory1(k,:);
[u1k,nloptions1,info] = nlmpcmove(nlobj1,x1k,lastMV1,[],[],nloptions1);
uHistory1(k+1,:) = u1k';
lastMV1 = u1k;
% Update states.
x1k = @(u1k,x1k) exocstrstateFcnCT1(x1k,u1k);
y1 = x1k;
xHistory1(k+1,:) = y1(end,:);
end
%%%%
fprintf(' k | u1(1) u1(2) x1(1) x1(2) x1(3) Time\n');
fprintf('----------------------------------------------------------\n');
%% This is the estimation part
for l=2:p+1
if l<=p-1
x1had(l,:)=xHistory1(l-1,:);
else
x1had(p,:)=xHistory1(p+1,:);
end
end
%%%%
Third, I want several robots to move together, and for the current position of the neighboring robot, the previous mode is used as an estimate for the neighboring robot.
Its code is as follows
Fourth, I want to show this on the plot, for example, they are connected in a rectangular shape, go from one point to another.
The nonlinear system is discrete
%%%%
It makes an error
Input arguments to function include colon operator. To input the colon character, use ':' instead.
Error in mpc1 (line 83)
xHistory1(k+1,:) = y1(end,:);
please guide me

Answers (1)

x1k = @(u1k,x1k) exocstrstateFcnCT1(x1k,u1k);
That is a function handle
y1 = x1k;
That copies the function handle but does not invoke the function
xHistory1(k+1,:) = y1(end,:);
That tries to treat the function handle as an array.
It looks to me as if y1 should be assigned the result of invoking the function handle, but it is not obvious to me what the arguments should be to the invocation.

10 Comments

According to the functions defined above, I want to get and update the output in each step and use the previous moments or the same previous steps for estimation or the same xhad and express your position to your neighbors.
nloptions1 = nlmpcmoveopt;
nloptions1.Parameters = {Ts};
%%
xHistory1 = x1(1,:);
Duration = 20;
lastMV1 = u1';
uHistory1 = lastMV1;
%%
for k = 1:(Duration/Ts)
t = linspace(k*Ts, (k+p-1)*Ts,p);
% Compute the control moves with reference previewing.
x1k = xHistory1(k,:);
[u1k,nloptions1,info] = nlmpcmove(nlobj1,x1k,lastMV1,[],[],nloptions1);
uHistory1(k+1,:) = u1k';
lastMV1 = u1k;
% Update states.
x1k = @(u1k,x1k) exocstrstateFcnCT1(x1k,u1k);
y1 = x1k;
xHistory1(k+1,:) = y1(end,:);
end
%%%%
I guess that perhaps
x1k = @(u1k,x1k) exocstrstateFcnCT1(x1k,u1k);
should be
x1k = exocstrstateFcnCT1(x1k,u1k);
but this is a guess.
This gives the error
Not enough input arguments.
Error in exocstrstateFcnCT1 (line 5)
for i=1:p
Error in mpc1 (line 81)
x1k =exocstrstateFcnCT1(x1k,u1k);
function x1=exocstrstateFcnCT1(x1,u1,p)
for i=1:p
x1=x1(i,:);
u1(1)=u1(i,1);
u1(2)=u1(i,1);
x1(i+1,:)=[0.9*cos(x1(3)) 0;0.9*sin(x1(3)) 0;0 0.9]*[u1(1);u1(2)]+[x1(1);x1(2);x1(3)];
end
end
Thank you thank you so much
Excuse me, I also have constraints for this function. How should I express constraints?
Should the value of " p " be written in the constraints section or should it be defined separately and only the formulas written?
Sorry, I have never worked with that part of MATLAB.
No, no, you do not have to say sorry
You helped me a lot, thank you

Sign in to comment.

Asked:

on 27 Oct 2020

Commented:

on 30 Oct 2020

Community Treasure Hunt

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

Start Hunting!