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

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

From: Minchang Zhang

Date: 9 Nov, 2012 21:55:16

Message: 1 of 3

This is a really weird problem.
I have the following code working all the time, but today it suddenly doesn't work and give me the error message as the subject title.

Code:
%nD='TiO2';
nD='FS';
%nD=1.46;

if nD=='TiO2'
    nd=1;
elseif nD=='FS'
    nd=2;
else nd=nD;
end

Please help!
Thanks a lot!

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

From: Greg Heath

Date: 9 Nov, 2012 22:24:15

Message: 2 of 3

"Minchang Zhang" wrote in message <k7ju44$45d$1@newscl01ah.mathworks.com>...
> This is a really weird problem.
> I have the following code working all the time, but today it suddenly doesn't work and give me the error message as the subject title.
>
> Code:
> %nD='TiO2';
> nD='FS';
> %nD=1.46;
>
> if nD=='TiO2'
> nd=1;
> elseif nD=='FS'
> nd=2;
> else nd=nD;
> end
>
> Please help!
> Thanks a lot!

HINT: What are the dimensions of 'FS' and 'TiO2'?

Hope his helps.

Greg

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

From: James Tursa

Date: 10 Nov, 2012 01:05:22

Message: 3 of 3

"Minchang Zhang" wrote in message <k7ju44$45d$1@newscl01ah.mathworks.com>...
> This is a really weird problem.
> I have the following code working all the time, but today it suddenly doesn't work and give me the error message as the subject title.
>
> Code:
> %nD='TiO2';
> nD='FS';
> %nD=1.46;
>
> if nD=='TiO2'
> nd=1;
> elseif nD=='FS'
> nd=2;
> else nd=nD;
> end

To compare strings in an if test, use a string comparison function like strcmp or strcmpi instead of == which is element-by-element.

James Tursa

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