Got Questions? Get Answers.
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 message help ??? Error using ==> mtimes

Subject: error message help ??? Error using ==> mtimes

From: Sam Hamie

Date: 1 Oct, 2010 18:32:20

Message: 1 of 8

Hello
I'm getting an error message every time I runt this code!
The error message is the following:
??? Error using ==> mtimes
Inner matrix dimensions must agree.

Because I'm multiplying arrays, I did use .* and ./ but the problem persisted.

Please help,
Thanks
Ish

phi = (-pi/2):(pi/1000):(pi/2);
%phi = 90;
theta = (0.01):(pi/1000):pi;
%theta = 90;
r=1;
fr=77*(1e+9);
c=(2.9986e+8)*1000; %mm/sec
lamda_o=c/fr; %mm
ko=(2*pi)/lamda_o;
h= 0.03;
width= 0.054;
const=((j)*ko*h*width*(exp((-j)*ko*r)))/(2*pi*r);
X=(ko*h/2)*cos(phi)*sin(theta);
Y=(ko*width/2)*cos(theta);
radiation= ((abs(const*(sin(X)/X)*(sin(Y)/Y)*sin(theta)))^2)/(2*120*(pi^2));

radiation

Subject: error message help ??? Error using ==> mtimes

From: Sean

Date: 1 Oct, 2010 18:40:05

Message: 2 of 8

"Sam Hamie" <Ismail.hamieh@gmail.com> wrote in message <i859fk$jdr$1@fred.mathworks.com>...
> Hello
> I'm getting an error message every time I runt this code!
> The error message is the following:
> ??? Error using ==> mtimes
> Inner matrix dimensions must agree.
>
> Because I'm multiplying arrays, I did use .* and ./ but the problem persisted.
>
> Please help,
> Thanks
> Ish
>
> phi = (-pi/2):(pi/1000):(pi/2);
> %phi = 90;
> theta = (0.01):(pi/1000):pi;
> %theta = 90;
> r=1;
> fr=77*(1e+9);
> c=(2.9986e+8)*1000; %mm/sec
> lamda_o=c/fr; %mm
> ko=(2*pi)/lamda_o;
> h= 0.03;
> width= 0.054;
> const=((j)*ko*h*width*(exp((-j)*ko*r)))/(2*pi*r);
> X=(ko*h/2)*cos(phi)*sin(theta);
> Y=(ko*width/2)*cos(theta);
> radiation= ((abs(const*(sin(X)/X)*(sin(Y)/Y)*sin(theta)))^2)/(2*120*(pi^2));
>
> radiation

quick work with the debugger (>> dbstop if error)
points to this line:
X=(ko*h/2)*cos(phi)*sin(theta);

whos ko h phi theta
  Name Size Bytes Class Attributes

  h 1x1 8 double
  ko 1x1 8 double
  phi 1x1001 8008 double
  theta 1x997 7976 double

Clearly there's going to be a dimensional error.

Subject: error message help ??? Error using ==> mtimes

From: Matt Fig

Date: 1 Oct, 2010 18:42:05

Message: 3 of 8

How would you suppose to multiply a 1x1001 vector, element-by-element, with a 1x997 vector?

Subject: error message help ??? Error using ==> mtimes

From: Sam Hamie

Date: 1 Oct, 2010 18:59:19

Message: 4 of 8

Sean,

I know that phi and theta are the problem but I'm not sure how to fix those?
How can you limit the array to make them the same?

Thanks,
Ish


"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i859u5$j7v$1@fred.mathworks.com>...
> "Sam Hamie" <Ismail.hamieh@gmail.com> wrote in message <i859fk$jdr$1@fred.mathworks.com>...
> > Hello
> > I'm getting an error message every time I runt this code!
> > The error message is the following:
> > ??? Error using ==> mtimes
> > Inner matrix dimensions must agree.
> >
> > Because I'm multiplying arrays, I did use .* and ./ but the problem persisted.
> >
> > Please help,
> > Thanks
> > Ish
> >
> > phi = (-pi/2):(pi/1000):(pi/2);
> > %phi = 90;
> > theta = (0.01):(pi/1000):pi;
> > %theta = 90;
> > r=1;
> > fr=77*(1e+9);
> > c=(2.9986e+8)*1000; %mm/sec
> > lamda_o=c/fr; %mm
> > ko=(2*pi)/lamda_o;
> > h= 0.03;
> > width= 0.054;
> > const=((j)*ko*h*width*(exp((-j)*ko*r)))/(2*pi*r);
> > X=(ko*h/2)*cos(phi)*sin(theta);
> > Y=(ko*width/2)*cos(theta);
> > radiation= ((abs(const*(sin(X)/X)*(sin(Y)/Y)*sin(theta)))^2)/(2*120*(pi^2));
> >
> > radiation
>
> quick work with the debugger (>> dbstop if error)
> points to this line:
> X=(ko*h/2)*cos(phi)*sin(theta);
>
> whos ko h phi theta
> Name Size Bytes Class Attributes
>
> h 1x1 8 double
> ko 1x1 8 double
> phi 1x1001 8008 double
> theta 1x997 7976 double
>
> Clearly there's going to be a dimensional error.

Subject: error message help ??? Error using ==> mtimes

From: Sam Hamie

Date: 1 Oct, 2010 19:00:24

Message: 5 of 8

hello Matt,

I know that phi and theta are the problem but I'm not sure how to fix those?
How can you limit the array to make them the same?

Thanks,
Ish

"Matt Fig" <spamanon@yahoo.com> wrote in message <i85a1t$qv2$1@fred.mathworks.com>...
> How would you suppose to multiply a 1x1001 vector, element-by-element, with a 1x997 vector?

Subject: error message help ??? Error using ==> mtimes

From: Sean

Date: 1 Oct, 2010 19:11:19

Message: 6 of 8


> I know that phi and theta are the problem but I'm not sure how to fix those?
> How can you limit the array to make them the same?

>>help linspace

Subject: error message help ??? Error using ==> mtimes

From: Matt Fig

Date: 2 Oct, 2010 00:05:23

Message: 7 of 8

If you have the memory for it, and if appropriate, you might need to do a mesh of these two variables using MESHGRID. Data interpretation will be up to you.


phi = (-pi./2):(pi./1000):(pi./2);
%phi = 90;
theta = (0.01):(pi./1000):pi;

[phi,theta]= meshgrid(phi,theta);

%theta = 90;
r=1;
fr=77.*(1e+9);
c=(2.9986e+8).*1000; %mm./sec
lamda_o=c./fr; %mm
ko=(2.*pi)./lamda_o;
h= 0.03;
width= 0.054;
const=((j).*ko.*h.*width.*(exp((-j).*ko.*r)))./(2.*pi.*r);
X=(ko.*h./2).*cos(phi).*sin(theta);
Y=(ko.*width./2).*cos(theta);
radiation= ((abs(const.*(sin(X)./X).*(sin(Y)./Y).*sin(theta))).^2)./(2.*120.*(pi.^2));
surf(phi,theta,radiation) % See what you are dealing with.

Subject: error message help ??? Error using ==> mtimes

From: John D'Errico

Date: 2 Oct, 2010 00:23:05

Message: 8 of 8

"Matt Fig" <spamanon@yahoo.com> wrote in message <i85a1t$qv2$1@fred.mathworks.com>...
> How would you suppose to multiply a 1x1001 vector, element-by-element, with a 1x997 vector?

Very, very carefully?

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