필터 지우기
필터 지우기

How to align two different sets of data whilst allowing a +- 10% range?

조회 수: 5 (최근 30일)
ASJ
ASJ 2018년 4월 8일
댓글: ASJ 2018년 4월 10일
Hi,
I am struggling to match two large sets of data (a table and a matrix) whilst allowing a + -range of 10% in the matching process. Small examples are given below.
The first table has 3 columns:
1-RP 2-DURATION 3-MAG
1 30 19.0960000000000
1 60 12.8000000000000
1 120 7.92000000000000
2 30 24.6400000000000
2 60 16.2000000000000
5 15 51.9100000000000
5 30 31.7200000000000
----etc
The 2nd matrix has 2 columns with actual data, eg:
1-DURATION 2-MAG
125 7.46875000000000
5 0.0312500000000000
30 0.218750000000000
0 0
65 16.0312500000000000
30 31.0312500000000000
My desired output would consist of merging the matrix and table by matching both the duration and mag values (whilst allowing a +-10% range in the matching process). The output is to create a 3rd and 4th column in the 2nd matrix shown above containing 3-RP 4-DURATION from the original table in the corresponding row. If no match is found, a return of the number zero is required.
Like this:
125 7.46875000000000 1 120
5 0.0312500000000000 0 0
30 0.218750000000000 0 0
0 0 0 0
65 16.0312500000000000 2 60
30 31.0312500000000000 5 30
I have tried various functions such as the stacking function but I am struggling to find a solution that works for a large data set and does what I need.
Any help or advise would be very appreciated.
Thanks!
  댓글 수: 3
ASJ
ASJ 2018년 4월 8일
thanks for the suggestion, I will do that now.

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

채택된 답변

Sergey Kasyanov
Sergey Kasyanov 2018년 4월 9일
Hi))
%converting and renaming of variables
t=table2array(table1);
m=matrix2;
%0.1 - range of choosing
d=1+0.1*[1,-1];
for i=1:size(m,1)
for j=1:size(t,1)
%that may be reciprocal k
% 1./k
k=[m(i,1)/t(j,2)
m(i,2)/t(j,3)];
if prod((k<d(1)).*(k>d(2)))
m(i,3:4)=[t(j,1),t(j,2)];
end
end
end
  댓글 수: 3
Sergey Kasyanov
Sergey Kasyanov 2018년 4월 10일
Yes.
k=[m(i,1)/t(j,2)
m(i,2)/t(j,3)];
k is a ratio between DURATIONS and MAGNITUDES accordingly k(1) and k(2).
(k<d(1)).*(k>d(2))
That is checking of values of ratios k both for upper and lower bounds. Operand .* is analog of logical AND.
prod((k<d(1)).*(k>d(2)))
That is analog of logical AND for values which are comprised in array.
if prod((k<d(1)).*(k>d(2)))
m(i,3:4)=[t(j,1),t(j,2)];
Save data if it is satisfying conditions.
ASJ
ASJ 2018년 4월 10일
Got it, thank you so much for taking the time to help and explain! :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by