How do i write a function containing a loop for two vectors?
조회 수: 1 (최근 30일)
이전 댓글 표시
Dear Community, I have to create 2 vectors one expressing an upper boundary of 5% and a lower boundary of 5%. These 5% each have to be "removed" from my original plot. My original plot is described on the x axis by milliseconds up to 20000ms and my y axis deals with the values between 0 and 1. The plot is called from a dataset with this command:
plot(sort(meanRandLike(20000,:))
If my lower and upper boundary are defined by
s=sort(meanRandLike(20000,:));
s(50)
s(950)
Now I would like to create a loop for both upper and lower boundary for 10000 values like this:
s=sort(meanRandLike(1,:));
lowerB(1) =s(1,50)
....
lowerB(1000) =s(1000, 50)
and the same for upper boundary:
upperB(1) = s(1,950)
....
upperB(1000)=(1,950)
Could somebody help me write this in a loop? Thank you very much!
댓글 수: 0
답변 (3개)
Brett Shoelson
2011년 3월 5일
Jenny, why on earth would you want to write that in a loop?(Is that a homework assignment?) And do you really need to calculate (and keep) the upperB and lowerB matrices? Or do you just want to eliminate them, keeping only the 5th through 95th percentiles? If the latter, you can just do something like this:
bounds = prctile(s,[5,95]);
keepvals = a(a>=bounds(1) & a<=bounds(2));
And, if you need them:
discards = setdiff(a,keepvals);
lowerB = discards(discards<=bounds(1));
upperB = discards(discards>=bounds(2));
Cheers, Brett
Brett Shoelson
2011년 3월 5일
I can tell you how to discard your outliers, but I can't tell you if you should. (Is that what you're asking?)
I would guess that that's kosher as long as you report your methods, but then i'm not a statistician.
Brett
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!