How to round a large array to the nearest factor of 0.0064
조회 수: 3 (최근 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
추가 답변 (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!
