I would like to filter out some vectors based on a percent of aggregate

조회 수: 3 (최근 30일)
I would like to filter some time series based on their weight of the overall aggregate. The weights are to be calculated based on the derived aggregate/components of the second last element in each vector (x1=20, x2=2, x3=62) The end result would be to extract the complete time series vectors satisfying the threshold. I would also appreciate suggested improvements to the code:
Threshold = *.2*
x1=[5 10 20 15 40 20 25]';
x2=[8 25 15 50 41 2 15]';
x3=[32 42 30 52 33 62 77]';
x=[x1 x2 x3];
sumx=sum(x')';
sumx=[sumx sumx sumx];
perx=x./sumx
perx=perx(4,:);
perx =
0.2381 0.0238 0.7381
Here x2 should be deleted since it falls below the threshold and a new object containing x1 and x3 vectors should get created.
x=[x1 x3];
  댓글 수: 3
Jeff
Jeff 2013년 9월 22일
Hi Image, you are on the right track thanks for your help. The one thing that was missing is that the threshold is based on the percentage that the second last element makes of the total of the three vectors along that element;
sumx=20+2+62 = 84 x1%=20/84=.2381 x2%=2/84=.0238 x3%=62/84=.7381
since threshold=.2 then x2%<threshold and x2 vector should be dropped;
Is that clearer?
Image Analyst
Image Analyst 2013년 9월 22일
Yes, see my new edited code below.

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

채택된 답변

Image Analyst
Image Analyst 2013년 9월 22일
편집: Image Analyst 2013년 9월 22일
See if this is what you want:
thresholdPercent = 0.2
x1=[5 10 20 15 40 20 25]';
x2=[8 25 15 50 41 2 15]';
x3=[32 42 30 52 33 62 77]';
% Sum them up
sumx = sum([x1,x2,x3], 2)
x=[];
% Get the value that each column will be compared to.
Threshold = thresholdPercent * sumx(end-1)
% Tack on x1 if it's above the threshold.
if x1(end-1) > Threshold
fprintf('Adding on x1:\n');
x = [x, x1]
end
% Tack on x2 if it's above the threshold.
if x2(end-1) > Threshold
fprintf('Adding on x2:\n');
x = [x, x2]
end
% Tack on x3 if it's above the threshold.
if x3(end-1) > Threshold
fprintf('Adding on x3:\n');
x = [x, x3]
end
% Get the means:
meanAcrossColumns = mean(x, 2)
  댓글 수: 3
Image Analyst
Image Analyst 2013년 9월 22일
It just prints out some debugging stuff to the command window - it's optional and you can remove it if you want.
Jeff
Jeff 2013년 9월 22일
Hi Imagine, just implemented your code with actual data I have and one question that comes up is how do I know which variable has passed this threshold test? Is there a way to not only store that variable in object x but to name it as well so that I know which variable I have? Much appreciated

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

추가 답변 (1개)

Jeff
Jeff 2013년 9월 25일
편집: Jeff 2013년 9월 25일
Found this in the matlab documentation just to share
Find the indices of values in a vector that are greater than a specified limit.
A = rand(1,10); limit = .75;
B = (A > limit); % B is a vector of logical values if any(B) fprintf('Indices of values > %4.2f: \n', limit); disp(find(B)) else disp('All values are below the limit.') end

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by