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

6 次查看(过去 30 天)
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
clear all
global kfiler d kmatrice phi kmes kcalc y s Rcmin kcalcmin Rc
kmatrice=[29.16;0;0;0;0];
kfiler=2000;
d=91e-6;
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];
kcalc=kmatrice*(2*kmatrice+(kfiler/(1+2*(kfiler*Rc/d)))-2*phi*(kmatrice-(kfiler/(1+2*(kfiler*Rc/d)))))/(2*kmatrice+(kfiler/(1+2*(kfiler*Rc/d)))+phi*(kmatrice-(kfiler/(1+2*(kfiler*Rc/d)))));
y= (kmes-kcalc)^2;
s= @(Rc)sum(y);
kcalcmin = fminsearch(s,kmatrice);
Rcmin=(kfiler/kcalcmin-1)*d/(2*kfiler);
Rcmin

采纳的回答

Sven
Sven 2011-11-29
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:
kfiler/(1+2*(kfiler*Rc/d))
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 个评论
TALA MOUSSA
TALA MOUSSA 2011-11-29
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.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2011-11-29
Please consider the possibility that you want to use ./ ( rdivide) instead of / ( mrdivide) in your code.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by