필터 지우기
필터 지우기

How to search an compare two arrays for certain criteria

조회 수: 1 (최근 30일)
Barnabas
Barnabas 2014년 1월 3일
편집: Barnabas 2014년 1월 3일
I have to arrays that are the same length with similar but not identical values. I need to compare from start to finish these arrays to see when array A is greater than or less than array B by 10% +/- 20. Once I find when those instance occur I need to plot data points 5 seconds before and 5 seconds after the event. Should I use an if and statement loop? Any help is appreciated, thanks.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 3일
This is not clear, give a numeric example and post the expected result
Barnabas
Barnabas 2014년 1월 3일
편집: Barnabas 2014년 1월 3일
Apologies, here is an example below:
A = [100 115 200]
B = [111 105 150]
I need to compare A(1) with B(1) and see if they are within 10% +/- 20. If the difference is greater than 10% +/- 20 then I need to mark that index position, and plot 5 data-points before and after the event.
So I would like a new array that would populate at what index points (in this case A(3)) the difference is greater than 10% +/- 20. I hope that helps. Below is what I have o far, but am not confident in the for loop statements accuracy.
TqRspns = rot90(EngTrqStatic);
TqRqst = (EngTrq_Rq_ESC);
% P = Percent Difference Requested for sort %
P = 10;
% PM = Plus/Minus Nm value for secondary sort %
PM = 20;
n = 1;
TqRqst1 = (interp1(TqRqst,1:0.50032725075316337285902503293808:126077));
Difference = abs(((TqRspns./TqRqst1)*100)-100);
index = find(Difference>P);
for n = 1:251988;
if (TqRqst1(n)>TqRspns(n)+PM);
Found(n) = n;
n+1;
end;
end;

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

답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 3일
mask = (A > 0.9 * B - 20) & (A < 1.1 * B + 20);
extended_mask = logical(filter(mask, ones(1,11)));
Now extended_mask selects the elements to be plotted. How to proceed with the actual plotting depends on what you want the output to look like when there are multiple events.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by