Why don't the Inner matrix dimensions agree when adding an extra variable?

I'm using multiple regression to obtain the coefficients from 3 predictor variables (x1, x2, x3, each a [1 x 20] array) and two outcome variables (x and y, each a [1 x 20] array). Using the following code:
X = [ones(length(x1),1) x1' x2' x3'];
B = X\devY';
B(1,:)=[]
J = B';
Z = null(J);
to import the [4 x 2] coefficients into a [2 x 3] Jacobian matrix (J) (removing the constant values) from which the null(J)is used to calculate an output known as the UCM using the following code:
for i = 1:N
UCM(:,i) = (Z'*dev(:,i))*Z;
end
This code works for 3 predictor and 2 output variables. However if I add an extra predictor variable (x4) (a [1 x 20] array) I get the following warning:
Error using ==> mtimes Inner matrix dimensions must agree.
Any help would be appreciated.

4 Comments

Please learn how to format code in this forum.
Z is a [3 x 1] array and dev is a [3 x 20] array (i.e. the deviations of three performance variables combined: x1, x2, and x3] using the following code:
[M,N] = size(data);
mn = mean(data,2);
dev = data-repmat(mn,1,N);
x1 = dev (1,:);
x2 = dev (2,:);
x3 = dev (3,:);
Hi guys,
if you're not already tired of my questions I have a bit more information to hopefully make a bit more sense. Any help would be appreciated.
I'm trying to see how joint angles of the right leg (predictor variables, X = x1, x2, x3 for the hip, knee, and ankle angles respectively each a [1 x 20] array) could potentially stablise the position of the right foot (outcome variables Y = x,y coordinate positions: both a [1 x 20] array) using linear regression.
"dev" (a [1 x 20] array for each predictor variable) is the deviations of joint angles from the mean joint angle configuration at each trial and projected onto the null-space or null(J)(Z = null(J)) using the following code:
for i = 1:N
UCM(:,i) = (Z'*dev(:,i))*Z;
end
The UCM is used to look at the control of a movement and is approximated linearly using the null space (Z) of the J matrix.
This code works for one frame (i.e. a [1 x 20] array) and a whole normalised movement cycle (i.e. a [101 x 20] array) for 3 predictor varibles (PV's) and 2 output variables (OV's) from a [3 x 1] Z array.
However when I increase the number of PV's to 4 (resulting in a [4 x 2] Z array) and 5 (resulting in a [5 x 2] Z array) with 2OV's, I get the following warning:
???Error using mm>mtimes
Inner matrix dimensions must agree
Therefore, i'm unable to analyse any data above three PV's. Can you help indentify where i'm going wrong?

Sign in to comment.

Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Asked:

on 22 Nov 2012

Community Treasure Hunt

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

Start Hunting!