Thread Subject: Skipped if statements

Subject: Skipped if statements

From: Jason Mickey

Date: 29 Oct, 2009 03:23:02

Message: 1 of 3

Why is my if statement being skipped? (The test if t==2 fails, even though the final value of t is 2). I have in a while loop

if (t==2.0000) || (t==0.2) || (t==0.8) || (t==1.0) || (t==2.0)
        figure
        contour(X,Y,Tnew);
end


Also, is there a way to title my figure with the value of t encoded in it? I tried

title('t = %1.3f',t)

But that didn't work.


Thanks.

Subject: Skipped if statements

From: nor ki

Date: 29 Oct, 2009 10:07:01

Message: 2 of 3

"Jason Mickey" <jmick175@gmail.com> wrote in message <hcb1qm$958$1@fred.mathworks.com>...
> Why is my if statement being skipped? (The test if t==2 fails, even though the final value of t is 2). I have in a while loop
>
> if (t==2.0000) || (t==0.2) || (t==0.8) || (t==1.0) || (t==2.0)
> figure
> contour(X,Y,Tnew);
> end
>
>
> Also, is there a way to title my figure with the value of t encoded in it? I tried
>
> title('t = %1.3f',t)
>
> But that didn't work.
>
>
> Thanks.

Hi Jason

numbers are not exact for reason of binarisation, they might have a small deviation so try

abs(t-2.0) < alloweddeviation

instead of

t==2.0

hth

kinor

Subject: Skipped if statements

From: Jos

Date: 29 Oct, 2009 12:38:01

Message: 3 of 3

"Jason Mickey" <jmick175@gmail.com> wrote in message <hcb1qm$958$1@fred.mathworks.com>...
* snip*

> Also, is there a way to title my figure with the value of t encoded in it? I tried
>
> title('t = %1.3f',t)

TITLE expects a string as input. Take a look at SPRINTF.

STR = sprintf('t %1.3f',t)
title (STR)

hth
Jos

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com