필터 지우기
필터 지우기

Find datapoints a specified distance apart in matrix using while loop

조회 수: 1 (최근 30일)
Emu
Emu 2023년 3월 27일
댓글: Emu 2023년 3월 27일
I have some data with positive integers (to_pos). I want to find and extract into a second matrix (spacedCrossPoints) datapoints that are a minimum of 30 from each other. So my desired output would be: 1214,2263,2320,8262,8292....
Here is my not working code so far:
gapBetweenCrosses = 30;
for cross = 2:length(t0_pos)-1;
i = cross;
if (((t0_pos(cross+1))-(t0_pos(i))) >= gapBetweenCrosses)% && (cross < ((length(t0_pos))-30)); %if gap between row greater than or equal to 30(s)
spacedCrossPoints(end+1,1) = t0_pos(cross+1); %insert values of crosspoints into matrix
elseif ((t0_pos(cross+1))) - (t0_pos(i)) < gapBetweenCrosses %&& cross < (length(t0_pos))-30; %if gap is less than 30. skips
%jump = 30-(((t0_pos(cross+1))) - (t0_pos(cross))); %calculate jump as difference between 30 and different between rows
while ((t0_pos(cross+1))) - (t0_pos(i)) < gapBetweenCrosses
cross = cross+1;
%spacedCrossPoints(end+1,1) = t0_pos(cross+1); %notes new value 30 past last value %NEED TO MAKE CROSS NOT EXCEED length t0_pos
end
end
cross = cross+1;
end
end
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 3월 27일
"I want to find and extract into a second matrix (spacedCrossPoints) datapoints that are a minimum of 30 from each other."
How does the above statement relate to this - "So my desired output would be: 1214,2263,2320,8262,8292...."
Do you want to obtain all the pair of points whose difference is >= gap?
Emu
Emu 2023년 3월 27일
In the attached dataset the datapoints that are 30 or more points from each other are as specified: 1214,2263,2320,8262,8292... They are not pairs.

댓글을 달려면 로그인하십시오.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 3월 27일
편집: Dyuman Joshi 2023년 3월 27일
Points which are >= 30 than the previous point starting with the 1st point -
load t0_pos.mat
gap=30;
k=1;
y=false(size(t0_pos));
y(k)=true;
%loop
while k<numel(t0_pos)
k=find(t0_pos - t0_pos(k) >= gap, 1);
y(k)=true;
end
out = t0_pos(y)'
out = 1×34
1214 2263 2320 8262 8292 8322 8434 8480 9014 9090 9149 9179 9215 14848 14904 15106 15149 15207 15372 15443 16330 16671 16708 20532 20590 20757 20809 23325 23355 23385
  댓글 수: 3
Dyuman Joshi
Dyuman Joshi 2023년 3월 27일
I have edited my answer, please check again.
Emu
Emu 2023년 3월 27일
that is amazing :) thank you so much !!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by