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:
Inner matrix dimensions must agree

Subject: Inner matrix dimensions must agree

From: Kirk

Date: 2 Oct, 2012 21:24:08

Message: 1 of 4

I am getting the "error using * Inner matrix dimensions must agree" error. However, I think my matrix dimensions do agree.

I have narrowed the problem down to the multiplication of two arrays

day <157776 x 1 double>
days <15776 x 1 double>

The attempted multiplication is:

calday = day * days;

This is awfully straightforward... what the heck am I not seeing?

Subject: Inner matrix dimensions must agree

From: Matt J

Date: 2 Oct, 2012 21:38:08

Message: 2 of 4



 calday = day .* days;

Subject: Inner matrix dimensions must agree

From: Nasser M. Abbasi

Date: 2 Oct, 2012 22:44:23

Message: 3 of 4

On 10/2/2012 4:24 PM, Kirk wrote:
> I am getting the "error using * Inner matrix dimensions must agree" error.
>However, I think my matrix dimensions do agree.
>
> I have narrowed the problem down to the multiplication of two arrays
>
> day <157776 x 1 double>
> days <15776 x 1 double>
>
> The attempted multiplication is:
>
> calday = day * days;
>
> This is awfully straightforward... what the heck am I not seeing?

If you want to use * then inner dimensions must agree.
They do not here clearly.

Else, use element by element product as Matt showed.


--Nasser
  

Subject: Inner matrix dimensions must agree

From: Steven_Lord

Date: 3 Oct, 2012 13:41:50

Message: 4 of 4



"Kirk" <kwythers.nospam@umn.edu> wrote in message
news:k4fm1o$9uv$1@newscl01ah.mathworks.com...
> I am getting the "error using * Inner matrix dimensions must agree" error.
> However, I think my matrix dimensions do agree.
> I have narrowed the problem down to the multiplication of two arrays
> day <157776 x 1 double>
> days <15776 x 1 double>

I'm assuming that one of the row sizes is a typo and they both have 157776
or 15776 rows.

> The attempted multiplication is:
>
> calday = day * days;
>
> This is awfully straightforward... what the heck am I not seeing?

Just listing the sizes of the two variables you're trying to multiply (and
assuming 15776 is the correct size; that's about 43 years, while 157776 is
around 430 years) shows the problem.

[15776 1] [15776 1]

Matrix multiplication requires the two innermost sizes to match; the number
of columns in the first matrix must be the same as the number of rows in the
second. In this case, they aren't. Two possible solutions, depending on what
you're trying to do:

1) Perform elementwise multiplication as Matt suggested, by replacing * with
.* in your expression. The result would be the same size as the two inputs.
2) Transpose one of the matrices. If you transpose the first, the sizes
become:

[1 15776] [15776 1]

and the result will be a 1-by-1. Basically this takes the dot product of the
two vectors.

http://en.wikipedia.org/wiki/Dot_product

If you transpose the second:

[15776 1] [1 15776]

you get a decent sized matrix.

http://en.wikipedia.org/wiki/Outer_product

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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