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!