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:
change format of numbers in a script

Subject: change format of numbers in a script

From: samira

Date: 5 Jul, 2011 01:25:25

Message: 1 of 2

Hi all
I am making a logical comparison between two computed values and then perform a command based on the results of the comparison.

Unfortunately, as I checked my code, I got that it doesn't use the whole number in the momory and uses the round of that number, for example this number is stored in the memory 1.173205080756888, but when it want to use this number for calculation it uses 1.1732. Therefore, it results error in logical comparison and affect my codes results.

Can you help me to make my code use the exact values stored in memory?

Thanks

Subject: change format of numbers in a script

From: TideMan

Date: 5 Jul, 2011 03:13:55

Message: 2 of 2

On Jul 5, 1:25 pm, "samira " <samira.rash...@gmail.com> wrote:
> Hi all
> I am making a logical comparison  between two computed values and then perform a command based on the results of the comparison.
>
> Unfortunately, as I checked my code, I got that it doesn't use the whole number in the momory and uses the round of that number, for example this number is stored in the memory 1.173205080756888, but when it want to use this number for calculation it uses 1.1732. Therefore, it results error in logical comparison and affect my codes results.
>
> Can you help me to make my code use the exact values stored in memory?
>
> Thanks

Don't do it that way.

Do it like this:
if abs(y-x) < tol
   % This means y is almost the same as x
end

where tol is a number small enough for it to work, e.g., 1e-3

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