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
 

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