http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712
MATLAB Central Newsreader  Simple question about number formatting
Feed for thread: Simple question about number formatting
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Wed, 07 Apr 2010 15:05:25 +0000
Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733833
Meagan
Hi all,<br>
<br>
I have a pretty simple question. I have a matrix V<br>
<br>
V =<br>
0 0 0.5000 0.5000 0.1250<br>
0.2000 0.2000 0.2000 0.2000 0.2000<br>
0.0000 0.5000 0.5000 0.0000 0.3750<br>
<br>
and I am trying to assign a variable to each position for example: x1=V(1,1); <br>
When I look at the value of x1, it equals 0 but when I type in z1=V(3,1); I get z1 =<br>
1.2246e017. How do I get z1=0?<br>
<br>
Thanks for your help.

Wed, 07 Apr 2010 15:07:59 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733835
us
On Apr 7, 5:05 pm, "Meagan " <meagan.mussel...@l3com.com> wrote:<br>
> Hi all,<br>
><br>
> I have a pretty simple question. I have a matrix V<br>
><br>
> V =<br>
> 0 0 0.5000 0.5000 0.1250<br>
> 0.2000 0.2000 0.2000 0.2000 0.2000<br>
> 0.0000 0.5000 0.5000 0.0000 0.3750<br>
><br>
> and I am trying to assign a variable to each position for example: x1=V(1,1);<br>
> When I look at the value of x1, it equals 0 but when I type in z1=V(3,1); I get z1 =<br>
> 1.2246e017. How do I get z1=0?<br>
><br>
> Thanks for your help.<br>
<br>
a hint:<br>
<br>
help round; % < and siblings...<br>
<br>
but, why would you want to do this(?!)...<br>
<br>
us

Wed, 07 Apr 2010 15:20:28 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733842
Matt Fig
Why is x1 a better way to access the value than V(1,1)? At least with the array, the addressing is built in to its very structure! What happens when V is 1000x1000, are you really going to assign one million variables to your workspace?

Wed, 07 Apr 2010 15:31:19 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733844
Meagan
I don't have to assign it to z1 but it still does not give me a value of 0 even though that is the value in my matrix. How do I format the rounding to give me zero instead of 1.2246e017? Later in my code I have an if statement that needs that value to be equal to zero.

Wed, 07 Apr 2010 15:40:10 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733846
us
On Apr 7, 5:31 pm, "Meagan " <meagan.mussel...@l3com.com> wrote:<br>
> I don't have to assign it to z1 but it still does not give me a value of 0 even though that is the value in my matrix. How do I format the rounding to give me zero instead of 1.2246e017? Later in my code I have an if statement that needs that value to be equal to zero.<br>
<br>
well... did you actually look at what you were told above(!?)...<br>
or are you just puking out another piece of thread...<br>
<br>
us

Wed, 07 Apr 2010 15:49:09 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733851
Mark Shore
"Meagan " <meagan.musselman@l3com.com> wrote in message <hpi8g7$ng8$1@fred.mathworks.com>...<br>
> I don't have to assign it to z1 but it still does not give me a value of 0 even though that is the value in my matrix. How do I format the rounding to give me zero instead of 1.2246e017? Later in my code I have an if statement that needs that value to be equal to zero.<br>
<br>
Using relational operators (in particular equal to) is bad practice with floating point numbers for reasons you are now becoming aware of. Search for some of the many detailed discussions in the forums.<br>
<br>
see also help eps

Wed, 07 Apr 2010 16:06:56 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733856
Loren Shure
In article <hpi6vl$rd9$1@fred.mathworks.com>, meagan.musselman@l<br>
3com.com says...<br>
> Hi all,<br>
> <br>
> I have a pretty simple question. I have a matrix V<br>
> <br>
> V =<br>
> 0 0 0.5000 0.5000 0.1250<br>
> 0.2000 0.2000 0.2000 0.2000 0.2000<br>
> 0.0000 0.5000 0.5000 0.0000 0.3750<br>
> <br>
> and I am trying to assign a variable to each position for example: x1=V(1,1); <br>
> When I look at the value of x1, it equals 0 but when I type in z1=V(3,1); I get z1 =<br>
> 1.2246e017. How do I get z1=0?<br>
> <br>
> Thanks for your help. <br>
> <br>
<br>
You need to be clear if you want to change the value or the display. <br>
For display, look at the help for format, disp, or sprintf. For values, <br>
look at round and friends.<br>
<br>
 <br>
Loren<br>
<a href="http://blogs.mathworks.com/loren">http://blogs.mathworks.com/loren</a><br>
<a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a>

Wed, 07 Apr 2010 16:30:21 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733868
Mark Shore
Loren Shure <loren.shure@mathworks.com> wrote in message <br>
snip<br>
> For display, look at the help for format, disp, or sprintf. For values, <br>
> look at round and friends.<br>
> <br>
>  <br>
> Loren<br>
<br>
"friends"? Is this a typo, or some arcane function I know nothing about? (Please  no jokes...)

Wed, 07 Apr 2010 16:35:41 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#733872
Roger Stafford
"Meagan " <meagan.musselman@l3com.com> wrote in message <hpi8g7$ng8$1@fred.mathworks.com>...<br>
> I don't have to assign it to z1 but it still does not give me a value of 0 even though that is the value in my matrix. How do I format the rounding to give me zero instead of 1.2246e017? Later in my code I have an if statement that needs that value to be equal to zero.<br>
<br>
What people are trying to say to you, Meagan, is that you are dead wrong when you say "it [referring to v(3,1)] still does not give me a value of 0 even though that is the value in my matrix". The value of V(3,1) is *not* actually zero, as is shown when you displayed it by itself by way of z1. The latter is the display you should have the greater confidence in.<br>
<br>
In the display of V as a whole, other values in it were in the range between 1 and 0.1 and the format was set at four decimal places, so the nearest value it could show for the v(3,1) entry given that restriction was "0.0000". This only means that it must lie somewhere between zero and 0.00005, (which in fact you found to be true.) Notice however that entries that were exactly zero such as V(1,1) were shown as "0", not "0.0000". Displaying "0.0000" rather than "0" is matlab's way of telling you that the corresponding entry is not precisely zero. It's the best that it can do given the constraints of displaying format for an entire array of values.<br>
<br>
Roger Stafford

Thu, 08 Apr 2010 14:29:26 +0000
Re: Simple question about number formatting
http://www.mathworks.com/matlabcentral/newsreader/view_thread/278712#734216
Loren Shure
In article <hpibut$n12$1@fred.mathworks.com>, mshore@magmageosciences.ca <br>
says...<br>
> Loren Shure <loren.shure@mathworks.com> wrote in message <br>
> snip<br>
> > For display, look at the help for format, disp, or sprintf. For values, <br>
> > look at round and friends.<br>
> > <br>
> >  <br>
> > Loren<br>
> <br>
> "friends"? Is this a typo, or some arcane function I know nothing about? (Please  no jokes...)<br>
> <br>
<br>
I meant friends of round  like fix, ceil, etc.<br>
<br>
 <br>
Loren<br>
<a href="http://blogs.mathworks.com/loren">http://blogs.mathworks.com/loren</a><br>
<a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a>