フィルターのクリア

How to search an compare two arrays for certain criteria

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by