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:
logical scalar values input

Subject: logical scalar values input

From: Snow White

Date: 25 May, 2009 15:36:01

Message: 1 of 5

Hi,

i wrote the following piece of code:

if (isnan(A) || isnan(B) || isnan(C) || isinf(A) || isinf(B) || isinf(C))
    value_chk=1;
else
    r = roots(p); %%computing roots of the equation inorder to find the refractive index
    [root_size rr]=size(r);
end

now i am getting these values although A=B=C are matrices of 1 or 0

??? Operands to the || and && operators must be convertible to logical scalar values.
Bye

Subject: logical scalar values input

From: Sadik

Date: 25 May, 2009 15:49:02

Message: 2 of 5

If the input to isnan is a matrix, it will return a matrix showing the locations of NaNs by 1. What you could do instead is replacing every matrix-like inputs with

sum(A(:))

so you would have

isnan(sum(A(:))) || isnan(sum(B(:))) || ...

and so on [since NaN + any number is NaN].

"Snow White" <gulesaman@gmail.com> wrote in message <gvedt1$f1n$1@fred.mathworks.com>...
> Hi,
>
> i wrote the following piece of code:
>
> if (isnan(A) || isnan(B) || isnan(C) || isinf(A) || isinf(B) || isinf(C))
> value_chk=1;
> else
> r = roots(p); %%computing roots of the equation inorder to find the refractive index
> [root_size rr]=size(r);
> end
>
> now i am getting these values although A=B=C are matrices of 1 or 0
>
> ??? Operands to the || and && operators must be convertible to logical scalar values.
> Bye

Subject: logical scalar values input

From: Matt Fig

Date: 25 May, 2009 15:59:03

Message: 3 of 5

You may want to use any(isnan(A)) etc, depending on what you are trying to do.

Subject: logical scalar values input

From: Steven Lord

Date: 25 May, 2009 16:23:03

Message: 4 of 5


"Snow White" <gulesaman@gmail.com> wrote in message
news:gvedt1$f1n$1@fred.mathworks.com...
> Hi,
>
> i wrote the following piece of code:
>
> if (isnan(A) || isnan(B) || isnan(C) || isinf(A) || isinf(B) || isinf(C))
> value_chk=1;
> else
> r = roots(p); %%computing roots of the equation inorder to find the
> refractive index
> [root_size rr]=size(r);
> end
>
> now i am getting these values although A=B=C are matrices of 1 or 0
>
> ??? Operands to the || and && operators must be convertible to logical
> scalar values.

That's correct. If any of A, B, or C are empty then ISNAN or ISINF on those
varaibles will not return a logical scalar value, but will return a logical
empty value.

By the way, you can use ~ISFINITE() on each variable to replace one call to
ISINF and one call to ISNAN.

--
Steve Lord
slord@mathworks.com

Subject: logical scalar values input

From: Snow White

Date: 25 May, 2009 16:36:01

Message: 5 of 5

thank you that worked so far#!
"Sadik " <sadik.hava@gmail.com> wrote in message <gveele$3nm$1@fred.mathworks.com>...
> If the input to isnan is a matrix, it will return a matrix showing the locations of NaNs by 1. What you could do instead is replacing every matrix-like inputs with
>
> sum(A(:))
>
> so you would have
>
> isnan(sum(A(:))) || isnan(sum(B(:))) || ...
>
> and so on [since NaN + any number is NaN].
>
> "Snow White" <gulesaman@gmail.com> wrote in message <gvedt1$f1n$1@fred.mathworks.com>...
> > Hi,
> >
> > i wrote the following piece of code:
> >
> > if (isnan(A) || isnan(B) || isnan(C) || isinf(A) || isinf(B) || isinf(C))
> > value_chk=1;
> > else
> > r = roots(p); %%computing roots of the equation inorder to find the refractive index
> > [root_size rr]=size(r);
> > end
> >
> > now i am getting these values although A=B=C are matrices of 1 or 0
> >
> > ??? Operands to the || and && operators must be convertible to logical scalar values.
> > Bye

Tags for 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