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

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
isnan Snow White 25 May, 2009 11:39:04
isinf Snow White 25 May, 2009 11:39:04
logical scalar ... Snow White 25 May, 2009 11:39:04
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com