How do i write a function containing a loop for two vectors?

1 view (last 30 days)
Jenny
Jenny on 5 Mar 2011
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!

Answers (3)

Brett Shoelson
Brett Shoelson on 5 Mar 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
  1 Comment
Jenny
Jenny on 5 Mar 2011
Thanks so much Brett!
I have just started with an introductory course in MatLab because I need it to analyze data I collected from a psychological experiment. My supervisor said the simplest way for me to do this would be with a loop.
Basically this is part of a bootstrapping test and I would like to compare my bootstrapped or pseudo hypothesis of 1000 random samples with my collected sample. If I plot my data with the within the pseudo distribution I can clearly see at which time (ms) my results become significant and thus exceed the 95% confidence interval.
So I guess I can eliminate the 5% each...?
Thank you very much for your help!
Best wishes
Jenny

Sign in to comment.


Brett Shoelson
Brett Shoelson on 5 Mar 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
  1 Comment
Jenny
Jenny on 5 Mar 2011
Hi Brett,
I just tried to integrate it in my function.
How is "a" defined in your example? Or how do I define it?

Sign in to comment.


Brett Shoelson
Brett Shoelson on 5 Mar 2011
Sorry, Jenny. Change those a's to s's. Brett

Community Treasure Hunt

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

Start Hunting!

Translated by