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 using ==> and Matrix dimensions must agree.

Subject: Error using ==> and Matrix dimensions must agree.

From: Russ Branaghan

Date: 16 May, 2009 22:33:02

Message: 1 of 4

Hello All,

I get a matrix dimensions must agree error when I try the following code in a function, but as far as I can tell the dimensions do agree. They are both 1 x 12 arrays. Any ideas?

Thanks,

Russ

Here is the code:
hmhp=sum((mean(x) > median(mean(x))) & (mean(y) >median(mean(y))));

And here is the error:
??? Error using ==> and
Matrix dimensions must agree.

Error in ==> getc2 at 13
        hmhp=sum((mean(x) > median(mean(x))) & (mean(y)
        >median(mean(y))));

Subject: Error using ==> and Matrix dimensions must agree.

From: Nasser Abbasi

Date: 16 May, 2009 23:06:09

Message: 2 of 4


"Russ Branaghan" <russ.branaghan.nospam@asu.edu> wrote in message
news:guneuu$42k$1@fred.mathworks.com...
> Hello All,
>
> I get a matrix dimensions must agree error when I try the following code
> in a function, but as far as I can tell the dimensions do agree. They are
> both 1 x 12 arrays. Any ideas?
>
> Thanks,
>
> Russ
>
> Here is the code:
> hmhp=sum((mean(x) > median(mean(x))) & (mean(y) >median(mean(y))));
>
> And here is the error:
> ??? Error using ==> and
> Matrix dimensions must agree.
>
> Error in ==> getc2 at 13
> hmhp=sum((mean(x) > median(mean(x))) & (mean(y)
> >median(mean(y))));

I get no error:

x=rand(1,12)
y=rand(1,12)
hmhp=sum((mean(x) > median(mean(x))) & (mean(y) >median(mean(y))))

You have something else wrong. do size on x and y, and do 'which -all' on
mean, median, sum to make sure you are using Matlab functions and not your
own.

good luck
--Nasser

Subject: Error using ==> and Matrix dimensions must agree.

From: Russ Branaghan

Date: 16 May, 2009 23:31:02

Message: 3 of 4

Hi Nasser,

Thanks for the info. Like you, I do not get an error when I run it in the workspace, but I do get the error when I try to run it in a function. I have checked the sizes, etc. and they all seem to be correct. It is very weird. I am running Matlab on the Mac. I wonder if it is some kind of bug with that version?

Thanks again for the help.

Russ


"Nasser Abbasi" <nma@12000.org> wrote in message <UBHPl.7189$Lr6.2786@flpi143.ffdc.sbc.com>...
>
> "Russ Branaghan" <russ.branaghan.nospam@asu.edu> wrote in message
> news:guneuu$42k$1@fred.mathworks.com...
> > Hello All,
> >
> > I get a matrix dimensions must agree error when I try the following code
> > in a function, but as far as I can tell the dimensions do agree. They are
> > both 1 x 12 arrays. Any ideas?
> >
> > Thanks,
> >
> > Russ
> >
> > Here is the code:
> > hmhp=sum((mean(x) > median(mean(x))) & (mean(y) >median(mean(y))));
> >
> > And here is the error:
> > ??? Error using ==> and
> > Matrix dimensions must agree.
> >
> > Error in ==> getc2 at 13
> > hmhp=sum((mean(x) > median(mean(x))) & (mean(y)
> > >median(mean(y))));
>
> I get no error:
>
> x=rand(1,12)
> y=rand(1,12)
> hmhp=sum((mean(x) > median(mean(x))) & (mean(y) >median(mean(y))))
>
> You have something else wrong. do size on x and y, and do 'which -all' on
> mean, median, sum to make sure you are using Matlab functions and not your
> own.
>
> good luck
> --Nasser
>

Subject: Error using ==> and Matrix dimensions must agree.

From: John D'Errico

Date: 17 May, 2009 00:45:03

Message: 4 of 4

"Russ Branaghan" <russ.branaghan.nospam@asu.edu> wrote in message <gunibl$424$1@fred.mathworks.com>...
> Hi Nasser,
>
> Thanks for the info. Like you, I do not get an error when I run it in the workspace, but I do get the error when I try to run it in a function. I have checked the sizes, etc. and they all seem to be correct. It is very weird. I am running Matlab on the Mac. I wonder if it is some kind of bug with that version?
>

No. I assure you it is not. What usually happens
here is someone does something silly, then
immediately assumes it is a bug in the basic
software.

Use the debugger to see these variables in the
function. Verify their sizes. Verify that you have
never defined variables with names like mean,
media, or sum, etc. Verify everything. Then
check again. And again.

John

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