フィルターのクリア

Define data list with a determine data distribution

4 ビュー (過去 30 日間)
Sabella Huang
Sabella Huang 2023 年 6 月 29 日
回答済み: Joe Vinciguerra 2023 年 6 月 29 日
Hi all,
I would like to use a min data distribution in my code. For example: I define each data positions are 500 or more. So when the first point difference is less than 700 with the second point, the second point will be deleted and the third point become the second one and so on. The results that I want like this:
mindist = 700; %minimum treshold for Data1
Data1 = [67106; 67732; 117467; 118467; 118967];
Data2 = [759.6421; 23.3729; 232.5324; 23.3729; 231.5324];
And I want the results to become:
Data1 = [67106; 117467; 118467];
Data2 = [759.6421; 232.5324; 23.3729];
Thank you, hope to hear your reply soon

回答 (1 件)

Joe Vinciguerra
Joe Vinciguerra 2023 年 6 月 29 日
% Generate some random data that's similar to yours
Data1 = sort(randi(1e4,[10,1])); % making sure the data is sorted
Data2 = randi(1e4, [10,1])/10;
% Display the starting data
[Data1, Data2]
ans = 10×2
1.0e+03 * 0.1480 0.3258 0.5420 0.8107 1.2350 0.4113 2.2130 0.9183 2.4090 0.4879 5.1600 0.1724 6.4910 0.2494 7.7980 0.4882 9.7600 0.1659 9.9870 0.5157
% Set the mindist
mindist = 700;
% Loop through all the data, starting with the first number
i = 1;
% While we are not at the end of the data set ...
while i < numel(Data1)
% ...and while the distance to the next item is too small
while (i < numel(Data1)) && (Data1(i+1) - Data1(i) < mindist)
% Remove the next item from the data set
Data1(i+1) = [];
Data2(i+1) = [];
end
% Go to the next item in the data set
i = i + 1;
end
% Display the results
[Data1, Data2]
ans = 7×2
1.0e+03 * 0.1480 0.3258 1.2350 0.4113 2.2130 0.9183 5.1600 0.1724 6.4910 0.2494 7.7980 0.4882 9.7600 0.1659

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by