필터 지우기
필터 지우기

Comparing elements of two uneven lists of numbers

조회 수: 2 (최근 30일)
Nadhya Polanco Ray
Nadhya Polanco Ray 2021년 9월 21일
댓글: Nadhya Polanco Ray 2021년 9월 21일
I am trying to compare numbers in two different lists to see if 2 subjects started the same action within 10 seconds of eachother. For example, I have one list of numbers
15
420
5778
6018
6388
and another list
414
1430
5762
6384
7098
What I would like to do is see if any number in list 2 is within 10 seconds of any number in list one.
For example, 420 and 414 are within 10 seconds of eachother, so I would like to take these numbers and mark the index of each number in its respective list.
The goal is to get the indexes I need for each list individually, and remove all of the other rows of each list seperately so only the correct numbers remain. In the above example the new lists would be:
420 and 414
6388 6384
The goal is for both lists to be the same length in the end. The data I am using here is time, so there is no chance of a number occuring more than once, and numbers are always in ascending order.

답변 (1개)

Chunru
Chunru 2021년 9월 21일
a1=[ 15
420
5778
6018
6388 ];
a2 = [ 414
1430
5762
6384
7098 ];
idx = find(abs(a1 - a2') <=10)
idx = 2×1
2 20
[i, j] = ind2sub([length(a1), length(a2)], idx)
i = 2×1
2 5
j = 2×1
1 4
% a1(2) and a2(1)
% a1(5) and a2(4)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by