From: Walter Roberson on 6 May 2010 13:52 yigit ozsahin wrote: > thank you for helping dividing to 10 and using command floor helped to > solve my problem. > just now wondering how can I found a lenght of a number. If the number is a positive integer, then NumLen = max(1,ceil(log10(TheNum))); If the number could be a negative integer, then you have to define whether the "length" of the number should include 1 for the negative sign (e.g., if you want to know how many characters it will print out as). If you do *not* want to include the negative sign as counting for 1 in the length, then: NumLen = max(1,ceil(log10(abs(TheNum)))); If you *do* want to count 1 for a negative sign, NumLen = max(1,ceil(log10(abs(TheNum)))) + (TheNum < 0); Note that none of the above formula will work for the value 0 -- conceptually 0 could be seen as having no width at all, so you have to define "length". If the number could have a fractional component, none of the above will work, and you have to define what you mean by the "length" of the number. For example, when you write 0.1 you probably think of the "length" as including 1 digit after the decimal point. Matlab cannot, however, exactly represent 0.1 in binary floating point, and the number that is store instead of 0.1 has about 25 digits in its decimal expansion.
First
|
Prev
|
Pages: 1 2 Prev: How to indicate current direction in simpowersystems Next: Problem deleting imrect |