Define data list with a determine data distribution
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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]
% 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]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!