MATLAB Answers

How to deal with dimensions of matrices being concatenated not consistent.

5 views (last 30 days)
Antoine Compagnie
Antoine Compagnie on 20 Jun 2016
Commented: John D'Errico on 14 Aug 2016
I am trying to create a Proportional Derivative controller with the following equation:
I need to first implement a PD controller for height control of the quadrotor. Then, tune the proportional gain (K p ) and derivative gain (K v ) in a file controller.m until the quadrotor converges quickly and smoothly to a step response input.
With e and dot e which can be calculated from the current and desired states (z, z des , z, ̇ z ̇ des ).
I tried:
function [ u ] = pd_controller(~, s, s_des, params)
%PD_CONTROLLER PD controller for the height
% s: 2x1 vector containing the current state [z; v_z]
% s_des: 2x1 vector containing desired state [z; v_z]
% params: robot parameters
u = 0;
e1=s_des*[1 0]-s*[1 0];
e2= s_des*[0 1]-s*[0 1];
K = [500 1];
% z(t) = dsolve(diff(z,t) == t*z)
u =params.mass*(([0 1]*s_des*-[0 1]*s)/(0.9)+e1*(K*[0 ;1])-e2*(K*[0;1])+params.gravity);
%u = params.mass*(params.gravity);
Yet, it gives
>> runsim
Initializing figures...
Simulation Running....
20 e1=s_des*[1 0]-s*[1 0];
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in sys_eom (line 9)
sdot = [s(2);
Error in height_control>@(t,s)sys_eom(t,s,controlhandle,trajhandle,params)
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in height_control (line 80)
[tsave, xsave] = ode45(@(t,s) sys_eom(t, s, controlhandle, trajhandle, params), timeint, x);
Error in runsim (line 17)
[t, z] = height_control(trajhandle, controlhandle);
Here is the sys_eom.m file:
function [ sdot ] = sys_eom(t, s, controlhandle, trajhandle, params)
% sys_eom Differential equation for the height control system
s_des = trajhandle(t);
u_des = controlhandle(t, s, s_des, params);
u_clamped = min(max(params.u_min, u_des), params.u_max);
sdot = [s(2);
u_clamped/params.mass - params.gravity];
John D'Errico
John D'Errico on 14 Aug 2016
Exactly. You can simply use the debugger to see the variables at the point this error arises. What shape and size are they? Think about why that happened. Why were they the sizes they were? What needs to happen?

Sign in to comment.

Answers (0)


Community Treasure Hunt

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

Start Hunting!