if difference between two values is smaller than replace by
古いコメントを表示
I have a vector that contains several time values. For the application I need to check if the difference between two values is smaller than 3e-6. If that's the case the second (higher) value shall be replaced with the first.
My approach would be for-loops but maybe there is a smarter and more efficient way to solve this?
5 件のコメント
Dyuman Joshi
2023 年 10 月 22 日
編集済み: Dyuman Joshi
2023 年 10 月 22 日
Are you taking the values adjacently/consecutively? or 1/2/.../n after the other? or randomly?
the cyclist
2023 年 10 月 22 日
Can you upload the data (or a small, representative sample)? You can use the paper clip icon in the INSERT section of the toolbar.
(There are several ways to store time values in MATLAB, and the syntax will be different depending on the data type.)
Kai
2023 年 10 月 22 日
移動済み: the cyclist
2023 年 10 月 22 日
Is each column processed independently?
It doesn't seem that any value is greater than the immediately preceding value by less than 3.e-6, but more than zero:
load("time.mat","time")
any((diff(time) > 0) & (diff(time) < 3.e-6),"all")
Walter Roberson
2023 年 10 月 22 日
編集済み: Walter Roberson
2023 年 10 月 22 日
load("time.mat","time")
dt = diff(time);
dt = dt(dt ~= 0);
min(dt)
So in all cases where the difference in times is < 3e-6, the two values are already identical.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!