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

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Star Strider
Star Strider il 24 Ott 2014
Modificato: Star Strider il 24 Ott 2014
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.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by