MATLAB Answers


Error using horzcat- dimensions of matrices being concatenated are not consistent

Asked by Olivia
on 24 Oct 2014
Latest activity Commented on by Star Strider
on 24 Oct 2014

br=log(brain); bd=log(body);

y = bd'; x_test = min(br)-500:max(br)+500;

A = [(br'.^2), br',ones(length(br)',1)]; the error is here

w = A\y;

A_test= [x_test'.^2,x_test',ones(length(x_test)',1)]; y_test =A_test*w;

(I'm trying to fit a 2nd order linear regression model to a set of data)

How do I fix the error?

br is a column vector. If I remove the transposes on the first two, I get another error- matrix dimensions don't agree in w=A\y. br is 65x1 and y is 1x65.

For A, the first column should contain the squares of the elements in br. The 2nd- just the elements in br. The 3rd- ones.


Sign in to comment.


1 Answer

Answer by Star Strider
on 24 Oct 2014
Edited by Star Strider
on 24 Oct 2014
 Accepted Answer

When I did this, the ‘A’ assignment did not throw any error:

br = 1:10;
A = [(br'.^2), br',ones(length(br)',1)];

My guess is that you transposed ‘br’ to a column vector somewhere else.

Just before the ‘A’ assignment, put:

sbr = size(br)

and see what the dimensions of ‘br’ are.