フィルターのクリア

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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by