Hi everybody,
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.
This is not elegant, but you could multiply your numbers by the xth power of 10 (where x is the number of decimal places you want to end up with), then use ceil, floor, round or trunc, 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. ;-)
function truncateDP(inValue,targetDP)// targetDP is the number of decimal places we wantVariable 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 to Wave in the code above, and maybe declare the whole thing as function/WAVE. In fact, since you're new:
function/WAVE truncateDP(inValue,targetDP)// targetDP is the number of decimal places we wantWave inValue
Variable targetDP
targetDP = round(targetDP)
inValue = round(inValue *(10^targetDP))/(10^targetDP)return inValue
end
Hi jdorsey!
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.
I'm not a big fan of the concept of 'significant digits', and the way it is often taught. I don't think reducing the precision of your data is a good solution to deal with uncertainty or noise.
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.
I don't see any advantage in reducing the significant figures in noisy data either, but I guess Christian understands his application better than we do...
[quote=741]While I'm only tangentially familiar with this subject, I think that the apparent lack of built-in truncation functionality in Igor is appropriate.[/quote]
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.
[quote=thomas_braun]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.[/quote]
ceil,floor,roundortrunc, 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. ;-)
To do a whole wave at once you'd just change the declaration of inValue from
VariabletoWavein the code above, and maybe declare the whole thing asfunction/WAVE. In fact, since you're new: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:
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