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

Thread Subject:
??? Error using ==> times Matrix dimensions must agree.

Subject: ??? Error using ==> times Matrix dimensions must agree.

From: Dimitrios Zlitidis

Date: 14 Dec, 2008 20:02:01

Message: 1 of 4

I've made this function:

"function y = myfun3(I)

 global R;
 global Imed;
 global si;
 global hm;
 global hp;
 
 
 a = atan(R/(hm-hp));
 rc = (0.67).*(I.^0.74).*(hp.^0.6);
 rs = (0.67).*(I.^0.74).*(hm.^0.6);
 c = sqrt( (hm - hp).^2 + R.^2);
 d = (rc.^2 - rs.^2 + c.^2)./(2.*c);
 b1 = acos(d./rc);
 
 W = (a-b1+pi./2).*rc;
 f= (1./(sqrt(2*pi)*si*I)).*exp(-(log(I)-log(Imed)).^2/(2*si^2));
 
 y = W.*f;"

In my main function I use it like this:
"J = quad(@myfun3, Ic, Im)
        SFFR = 0.2*Ng*J"

The message I take is:
"??? Error using ==> times
Matrix dimensions must agree.

Error in ==> myfun3 at 11
 rc = (0.67).*(I.^0.74).*(hp.^0.6);

Error in ==> quad at 77
y = f(x, varargin{:});

Error in ==> Eriksson_gui>pushbutton2_Callback at 411
        J = quad(@myfun3, Ic, Im)

Error in ==> gui_mainfcn at 96
        feval(varargin{:});

Error in ==> Eriksson_gui at 42
    gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uicontrol Callback"

What do I do wrong?!?!?!

Subject: ??? Error using ==> times Matrix dimensions must agree.

From: Dave Brackett

Date: 14 Dec, 2008 21:00:04

Message: 2 of 4

"Dimitrios Zlitidis" <dimitriszli@gmail.com> wrote in message <gi3onp$8g9$1@fred.mathworks.com>...
> I've made this function:
>
> "function y = myfun3(I)
>
> global R;
> global Imed;
> global si;
> global hm;
> global hp;
>
>
> a = atan(R/(hm-hp));
> rc = (0.67).*(I.^0.74).*(hp.^0.6);
> rs = (0.67).*(I.^0.74).*(hm.^0.6);
> c = sqrt( (hm - hp).^2 + R.^2);
> d = (rc.^2 - rs.^2 + c.^2)./(2.*c);
> b1 = acos(d./rc);
>
> W = (a-b1+pi./2).*rc;
> f= (1./(sqrt(2*pi)*si*I)).*exp(-(log(I)-log(Imed)).^2/(2*si^2));
>
> y = W.*f;"
>
> In my main function I use it like this:
> "J = quad(@myfun3, Ic, Im)
> SFFR = 0.2*Ng*J"
>
> The message I take is:
> "??? Error using ==> times
> Matrix dimensions must agree.
>
> Error in ==> myfun3 at 11
> rc = (0.67).*(I.^0.74).*(hp.^0.6);
>
> Error in ==> quad at 77
> y = f(x, varargin{:});
>
> Error in ==> Eriksson_gui>pushbutton2_Callback at 411
> J = quad(@myfun3, Ic, Im)
>
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
>
> Error in ==> Eriksson_gui at 42
> gui_mainfcn(gui_State, varargin{:});
>
> ??? Error while evaluating uicontrol Callback"
>
> What do I do wrong?!?!?!

find the size of each variable in the offending line using 'size'. can you give an example of I and hp?

Subject: ??? Error using ==> times Matrix dimensions must agree.

From: Dimitrios Zlitidis

Date: 14 Dec, 2008 22:42:02

Message: 3 of 4

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <gi3s4k$2ms$1@fred.mathworks.com>...
> "Dimitrios Zlitidis" <dimitriszli@gmail.com> wrote in message <gi3onp$8g9$1@fred.mathworks.com>...
> > I've made this function:
> >
> > "function y = myfun3(I)
> >
> > global R;
> > global Imed;
> > global si;
> > global hm;
> > global hp;
> >
> >
> > a = atan(R/(hm-hp));
> > rc = (0.67).*(I.^0.74).*(hp.^0.6);
> > rs = (0.67).*(I.^0.74).*(hm.^0.6);
> > c = sqrt( (hm - hp).^2 + R.^2);
> > d = (rc.^2 - rs.^2 + c.^2)./(2.*c);
> > b1 = acos(d./rc);
> >
> > W = (a-b1+pi./2).*rc;
> > f= (1./(sqrt(2*pi)*si*I)).*exp(-(log(I)-log(Imed)).^2/(2*si^2));
> >
> > y = W.*f;"
> >
> > In my main function I use it like this:
> > "J = quad(@myfun3, Ic, Im)
> > SFFR = 0.2*Ng*J"
> >
> > The message I take is:
> > "??? Error using ==> times
> > Matrix dimensions must agree.
> >
> > Error in ==> myfun3 at 11
> > rc = (0.67).*(I.^0.74).*(hp.^0.6);
> >
> > Error in ==> quad at 77
> > y = f(x, varargin{:});
> >
> > Error in ==> Eriksson_gui>pushbutton2_Callback at 411
> > J = quad(@myfun3, Ic, Im)
> >
> > Error in ==> gui_mainfcn at 96
> > feval(varargin{:});
> >
> > Error in ==> Eriksson_gui at 42
> > gui_mainfcn(gui_State, varargin{:});
> >
> > ??? Error while evaluating uicontrol Callback"
> >
> > What do I do wrong?!?!?!
>
> find the size of each variable in the offending line using 'size'. can you give an example of I and hp?


hp is a variable I give, it's a number, for example 5.41. I is the variable I use to integrate with quad.

Subject: ??? Error using ==> times Matrix dimensions must agree.

From: Dave Brackett

Date: 15 Dec, 2008 09:20:03

Message: 4 of 4

"Dimitrios Zlitidis" <dimitriszli@gmail.com> wrote in message <gi423q$eke$1@fred.mathworks.com>...
> "Dave Brackett" <davebrackett@hotmail.com> wrote in message <gi3s4k$2ms$1@fred.mathworks.com>...
> > "Dimitrios Zlitidis" <dimitriszli@gmail.com> wrote in message <gi3onp$8g9$1@fred.mathworks.com>...
> > > I've made this function:
> > >
> > > "function y = myfun3(I)
> > >
> > > global R;
> > > global Imed;
> > > global si;
> > > global hm;
> > > global hp;
> > >
> > >
> > > a = atan(R/(hm-hp));
> > > rc = (0.67).*(I.^0.74).*(hp.^0.6);
> > > rs = (0.67).*(I.^0.74).*(hm.^0.6);
> > > c = sqrt( (hm - hp).^2 + R.^2);
> > > d = (rc.^2 - rs.^2 + c.^2)./(2.*c);
> > > b1 = acos(d./rc);
> > >
> > > W = (a-b1+pi./2).*rc;
> > > f= (1./(sqrt(2*pi)*si*I)).*exp(-(log(I)-log(Imed)).^2/(2*si^2));
> > >
> > > y = W.*f;"
> > >
> > > In my main function I use it like this:
> > > "J = quad(@myfun3, Ic, Im)
> > > SFFR = 0.2*Ng*J"
> > >
> > > The message I take is:
> > > "??? Error using ==> times
> > > Matrix dimensions must agree.
> > >
> > > Error in ==> myfun3 at 11
> > > rc = (0.67).*(I.^0.74).*(hp.^0.6);
> > >
> > > Error in ==> quad at 77
> > > y = f(x, varargin{:});
> > >
> > > Error in ==> Eriksson_gui>pushbutton2_Callback at 411
> > > J = quad(@myfun3, Ic, Im)
> > >
> > > Error in ==> gui_mainfcn at 96
> > > feval(varargin{:});
> > >
> > > Error in ==> Eriksson_gui at 42
> > > gui_mainfcn(gui_State, varargin{:});
> > >
> > > ??? Error while evaluating uicontrol Callback"
> > >
> > > What do I do wrong?!?!?!
> >
> > find the size of each variable in the offending line using 'size'. can you give an example of I and hp?
>
>
> hp is a variable I give, it's a number, for example 5.41. I is the variable I use to integrate with quad.

So are none of the variables in the rc line matrices? Why do you have all of the element by element multiplication? Can you give an example of I?

Have you tried clearing your variables using 'clear' and trying again?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us