How do i write a function containing a loop for two vectors?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
Brett Shoelson
am 5 Mär. 2011
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
am 5 Mär. 2011
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
Siehe auch
Kategorien
Mehr zu Data Distribution Plots 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!