How to reduce the number of decimal places in a wave?
christian
I would like to decrease the number of decimal places in a wave. Using the Table-->Digits menu, only the visualization is changed.
I would like to change the original data.
Thank you in advance!
ceil
,floor
,round
ortrunc
, and finally divide the result by the original power of ten.EDIT:
Here you go. There's probably an in-built function to do this but I couldn't find it. Hahaha - try finding the command help for WaveList for example. ;-)
// targetDP is the number of decimal places we want
Variable inValue, targetDP
targetDP = round(targetDP)
inValue = round(inValue * (10^targetDP)) / (10^targetDP)
return inValue
end
To do a whole wave at once you'd just change the declaration of inValue from
Variable
toWave
in the code above, and maybe declare the whole thing asfunction/WAVE
. In fact, since you're new:// targetDP is the number of decimal places we want
Wave inValue
Variable targetDP
targetDP = round(targetDP)
inValue = round(inValue * (10^targetDP)) / (10^targetDP)
return inValue
end
EDIT 2: Why on Earth do you want to do this?
March 17, 2011 at 10:57 am - Permalink
Thank you for your quick reply!
You're right a built-in command or menu-item :-) would be great!
I need to reduce the number of decimal places because I have noise in the last digit of my data!
After I want to sort the wave according to another key-wave.
Thank you again!
March 17, 2011 at 11:30 am - Permalink
If you wish to minimize the impact of noise, I'd suggest you to use smoothing instead. If you want to report uncertainties, then add explicit error estimates or error bars.
While I'm only tangentially familiar with this subject, I think that the apparent lack of built-in truncation functionality in Igor is appropriate.
March 17, 2011 at 01:35 pm - Permalink
March 17, 2011 at 01:41 pm - Permalink
In the area of displaying numbers in a panel or so, it is appropriate to round data. The sprintf modifiers don't round, they only cut off.
March 17, 2011 at 01:50 pm - Permalink
I'm not sure I follow exactly:
Printf "%.3g\r", 3.4547 => 3.45
Looks like it's rounding, not truncating, to me. Sprintf gives the same results.
March 17, 2011 at 02:26 pm - Permalink
Sorry for the confusion.
March 18, 2011 at 02:03 am - Permalink