Filter löschen
Filter löschen

How to search an compare two arrays for certain criteria

2 Ansichten (letzte 30 Tage)
Barnabas
Barnabas am 3 Jan. 2014
Bearbeitet: Barnabas am 3 Jan. 2014
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 3 Jan. 2014
This is not clear, give a numeric example and post the expected result
Barnabas
Barnabas am 3 Jan. 2014
Bearbeitet: Barnabas am 3 Jan. 2014
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;

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 3 Jan. 2014
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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by