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: salman

Date: 17 May, 2011 03:55:04

Message: 1 of 4


Dear friends,

Have a good day,

i am getting this message "Error using times, MD must agree",
here are my three lines of code;

t=linspace(0,.0000001,200)
z=linspace(-.0002,.0002,200);
Initial_value=(exp(-(z.^2)./L.^2).*cos(z))./z;
E_1=vee_1*(Y(:,3).*t)+initial_value.*(z- vee_1*t);%------this is where the error comes

Y(:,3) is of size 200x1;


i dont know why this error comes, as i have checked the syntax and logic, it seems correct to me, yet its giving this error.

your help is greatly appreciated.

thanks alot

Subject: Error using times, Matrix dimensions must agree

From: Roger Stafford

Date: 17 May, 2011 04:19:03

Message: 2 of 4

"salman " <salmanabdullah9@gmail.com> wrote in message <iqsrio$kfj$1@newscl01ah.mathworks.com>...
>
> Dear friends,
>
> Have a good day,
>
> i am getting this message "Error using times, MD must agree",
> here are my three lines of code;
>
> t=linspace(0,.0000001,200)
> z=linspace(-.0002,.0002,200);
> Initial_value=(exp(-(z.^2)./L.^2).*cos(z))./z;
> E_1=vee_1*(Y(:,3).*t)+initial_value.*(z- vee_1*t);%------this is where the error comes
>
> Y(:,3) is of size 200x1;
>
>
> i dont know why this error comes, as i have checked the syntax and logic, it seems correct to me, yet its giving this error.
>
> your help is greatly appreciated.
>
> thanks alot
- - - - - - - -
  The multiplication in "(Y(:,3).*t)" is invalid since Y(:,3) is a column vector and t is a row vector. They must be the same size to use ".*". Also you should make sure that "vee_1" is a scalar or you will have other troubles.

Roger Stafford

Subject: Error using times, Matrix dimensions must agree

From: salman

Date: 17 May, 2011 05:39:02

Message: 3 of 4

"Roger Stafford" wrote in message <iqssvn$ob1$1@newscl01ah.mathworks.com>...
> "salman " <salmanabdullah9@gmail.com> wrote in message <iqsrio$kfj$1@newscl01ah.mathworks.com>...
> >
> > Dear friends,
> >
> > Have a good day,
> >
> > i am getting this message "Error using times, MD must agree",
> > here are my three lines of code;
> >
> > t=linspace(0,.0000001,200)
> > z=linspace(-.0002,.0002,200);
> > Initial_value=(exp(-(z.^2)./L.^2).*cos(z))./z;
> > E_1=vee_1*(Y(:,3).*t)+initial_value.*(z- vee_1*t);%------this is where the error comes
> >
> > Y(:,3) is of size 200x1;
> >
> >
> > i dont know why this error comes, as i have checked the syntax and logic, it seems correct to me, yet its giving this error.
> >
> > your help is greatly appreciated.
> >
> > thanks alot
> - - - - - - - -
> The multiplication in "(Y(:,3).*t)" is invalid since Y(:,3) is a column vector and t is a row vector. They must be the same size to use ".*". Also you should make sure that "vee_1" is a scalar or you will have other troubles.
>
> Roger Stafford

Dear Roger,

if i change the above equation and replace Y(:,3) by [Y(:,3)]', so now this becomes and row vector. after this however, the previous error is gone, but now i want to create the mesh from t and z and then get surface plot for E(z,t). but it says

Warning: Matrix dimensions must agree, not rendering mesh.

i used this one;

E_1=vee_1*((Y(:,3))'.*t)+Initial_value.*(z- t);
meshgrid(t,z);
surf(t,z,E_1)

where;

size(z)=1 200
size(t)=1 200
size(Y(:,3)')=1 200
size(Initial_value)=1 200,

i will be grateful for help.

thanks

Subject: Error using times, Matrix dimensions must agree

From: Greg Heath

Date: 17 May, 2011 15:25:50

Message: 4 of 4

On May 16, 11:55 pm, "salman " <salmanabdull...@gmail.com> wrote:
> Dear friends,
>
> Have a good day,
>
> i am getting this message "Error using times, MD must agree",
> here are my three lines of code;
>
> t=linspace(0,.0000001,200)
> z=linspace(-.0002,.0002,200);
> Initial_value=(exp(-(z.^2)./L.^2).*cos(z))./z;
> E_1=vee_1*(Y(:,3).*t)+initial_value.*(z- vee_1*t);%------this is where the error comes
>
> Y(:,3) is of size 200x1;
>
> i dont know why this error comes, as i have checked the syntax and logic, it seems
> correct to me, yet its giving this error.

"seems" is not good enough ...
check the matrix sizes before multiplication

help size
doc size

Hope this helps.

Greg

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