Thread Subject: Error using ==> mtimes when I'm not dealing with matrices at all

Subject: Error using ==> mtimes when I'm not dealing with matrices at all

From: David Migl

Date: 31 May, 2008 04:48:02

Message: 1 of 4

Hi,

I am trying to graph the parametric function
x=t*cos(t)
y=t*sin(t)

Matlab doesn't like these equations; it stops at the first
one and gives me the error message:

??? Error using ==> mtimes
Inner matrix dimensions must agree.

My script runs like this:
clear; clc; close all;
t=linspace (0,6*pi)
x=t*cos(t)
y=t*sin(t)
plot(x,y)

I am completely baffled why I should receive the error
message. I begin my .m file by clearing everything: clear;
clc; close all;, and the calculations I am doing have
absolutely nothing to do with matrices.

Does anyone have any insights into this?

Subject: Error using ==> mtimes when I'm not dealing with matrices at all

From: Roger Stafford

Date: 31 May, 2008 05:04:01

Message: 2 of 4

"David Migl" <migl.spam@gmail.com> wrote in message <g1qla2$ise
$1@fred.mathworks.com>...
> Hi,
>
> I am trying to graph the parametric function
> x=t*cos(t)
> y=t*sin(t)
>
> Matlab doesn't like these equations; it stops at the first
> one and gives me the error message:
>
> ??? Error using ==> mtimes
> Inner matrix dimensions must agree.
>
> My script runs like this:
> clear; clc; close all;
> t=linspace (0,6*pi)
> x=t*cos(t)
> y=t*sin(t)
> plot(x,y)
>
> I am completely baffled why I should receive the error
> message. I begin my .m file by clearing everything: clear;
> clc; close all;, and the calculations I am doing have
> absolutely nothing to do with matrices.
>
> Does anyone have any insights into this?
----------------
  You are using the '*' operator improperly. What you want is '.*' instead.
When you say

 t*cos(t)

matlab attempts to do matrix multiplication on two 100-element row vectors
and this is impossible for it to do, because the inner dimensions do not
match, just as the error message says.

  Write

 x = t.*cos(t);
 y = t.*sin(t);

Roger Stafford

Subject: Error using ==> mtimes when I'm not dealing with matrices at all

From: Kenneth Eaton

Date: 31 May, 2008 05:04:01

Message: 3 of 4

"David Migl" <migl.spam@gmail.com> wrote in message <g1qla2
$ise$1@fred.mathworks.com>...
> Hi,
>
> I am trying to graph the parametric function
> x=t*cos(t)
> y=t*sin(t)
>
> Matlab doesn't like these equations; it stops at the first
> one and gives me the error message:
>
> ??? Error using ==> mtimes
> Inner matrix dimensions must agree.
>
> My script runs like this:
> clear; clc; close all;
> t=linspace (0,6*pi)
> x=t*cos(t)
> y=t*sin(t)
> plot(x,y)
>
> I am completely baffled why I should receive the error
> message. I begin my .m file by clearing everything: clear;
> clc; close all;, and the calculations I am doing have
> absolutely nothing to do with matrices.
>
> Does anyone have any insights into this?

Try using .* instead of * for computing x and y.

Ken

Subject: Error using ==> mtimes when I'm not dealing with matrices at all

From: David Migl

Date: 31 May, 2008 05:20:03

Message: 4 of 4

Ah, that makes sense, I see what matlab is trying to do now.
Thanks for for your quick response and help!

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com