Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

?? Error using ==> mrdivide Matrix dimensions must agree.

Asked by TALA MOUSSA on 29 Nov 2011

hi , Im a beginner in using matlab , i tried several times to debug my program but the error is still the same!! can you help me please:) Thanks

clear all
global kfiler d kmatrice phi kmes kcalc y s Rcmin kcalcmin Rc
kmes = [29.16;31.51;36.33;39.9;44.3];
phi = [0 0 0 0 0;0 7.4 0 0 0;0 0 11.52 0 0; 0 0 0 18.44 0;0 0 0 0 23.88];
y= (kmes-kcalc)^2;
s= @(Rc)sum(y);
kcalcmin = fminsearch(s,kmatrice);  






No products are associated with this question.

2 Answers

Answer by Sven on 29 Nov 2011
Accepted answer

Rc is empty (it gets initialised as a global variable but nothing is assigned to it), but it's used in your calc=... calculation.

Was this intentional?

The problem here is that anything multiplied by an empty [] will return []. And any non-empty matrix divided by an empty matrix will cause an error.

The final part of your calculation:


Is one such part. kfiler is not empty, but Rc (and consequently (1+2(kfiler*Rc/d))* is empty.

You'll get the same error if you type in:

100 / []

One small suggesion: break up your calculation into a few lines. Otherwise it will be a complete nightmare to debug because all error messages will point to this one huge line (which doesn't help you track them down)

1 Comment

TALA MOUSSA on 29 Nov 2011

Thanks Sven , my problem is to find a minimum of s whis is the sum of y by the least square regression. So when s is minimun i have to search the minimum value of Rc.

Answer by Walter Roberson on 29 Nov 2011

Please consider the possibility that you want to use ./ ( rdivide) instead of / ( mrdivide) in your code.

1 Comment

TALA MOUSSA on 30 Nov 2011

Is anyone knows how to use the least square regression method in matlab?

Walter Roberson

Contact us