How to round a large array to the nearest factor of 0.0064
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have an array of data that is a 92246x1 double. The data has been retrieved from a sensor that is outputting in what appears to be steps of 0.0064V. This data has some noise present so I am wanting to round the data to the nearest interval of 0.0064V, what is the easiest way to do this? Thanks in advance
0 个评论
采纳的回答
Star Strider
2018-11-8
I am not certain what you want.
Three options:
A = rand(20,1); % Create Data
R1 = rem(A, 0.0064);
R2 = quant(A, 0.0064);
R3 = round(A/0.0064);
Q = [A, R1, R2, R3]; % Compare Results
The quant (link) function is now (in R2018b) in the Deep Learning Toolbox. I have no idea where it was in earlier releases.
更多回答(2 个)
John D'Errico
2018-11-8
编辑:John D'Errico
2018-11-8
Hint:
What would happen if you divided the entire array by 0.0064?
What if you then rounded the result to the nearest integer?
Finally, multiply by 0.0064. So
y = 0.0064*round(x/0.0064);
Note that all of this is perfectly vectorized, so the size of your array is irrelevant. And finally, see that you need to be careful in the end, because the final result will not actually be a multiple of 0.0064.This because 0.0064 is not representable exactly as a double. It will be as close as possible however.
0 个评论
Fangjun Jiang
2018-11-8
编辑:Fangjun Jiang
2018-11-8
x-rem(x,0.0064)
It is the floor() effect. If you want "round" effect, you might need a few lines more. This example assumes scalar input but can be vectorized.
c=0.0064;
r=rem(x,c)
if r<c/2
y=x-r;
else
y=x-r+c;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!