필터 지우기
필터 지우기

How to round a large array to the nearest factor of 0.0064

조회 수: 1 (최근 30일)
Jamie England
Jamie England 2018년 11월 8일
댓글: Star Strider 2018년 11월 8일
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

채택된 답변

Star Strider
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
Jamie England
Jamie England 2018년 11월 8일
This is exactly what I was in need of, thank you. The data I am retrieving looks as follows. There seems to be set levels at intervals of 0.0064V so wanted to attempt to approximately remove some of the noise
Star Strider
Star Strider 2018년 11월 8일
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

John D'Errico
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.

Fangjun Jiang
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by