How to round a large array to the nearest factor of 0.0064
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jamie England
el 8 de Nov. de 2018
Comentada: Star Strider
el 8 de Nov. de 2018
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 comentarios
Respuesta aceptada
Star Strider
el 8 de Nov. de 2018
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 comentarios
Más respuestas (2)
John D'Errico
el 8 de Nov. de 2018
Editada: John D'Errico
el 8 de Nov. de 2018
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 comentarios
Fangjun Jiang
el 8 de Nov. de 2018
Editada: Fangjun Jiang
el 8 de Nov. de 2018
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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!