Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Generate random sample

Subject: Generate random sample

From: kk KKsingh

Date: 5 Mar, 2010 21:11:20

Message: 1 of 5

Generate a random sample..from N samples and it should be even always, what should i add it i dont wana use loop thinng

kn1=randperm(N);
% Randomly eliminating some samples
percent=.70 %70 percent
kn2=kn1(1:ceil(percent*N));
% sorting random chosen traces in ascending order
z=[sort(kn2)];

z should always be even number of samples, how to get it ..i some time get them odd

Subject: Generate random sample

From: nanren888

Date: 5 Mar, 2010 21:47:22

Message: 2 of 5

"kk KKsingh" <akikumar1983@gmail.com> wrote in message <hmrs1o$jhb$1@fred.mathworks.com>...
> Generate a random sample..from N samples and it should be even always, what should i add it i dont wana use loop thinng
>
> kn1=randperm(N);
> % Randomly eliminating some samples
> percent=.70 %70 percent
> kn2=kn1(1:ceil(percent*N));
> % sorting random chosen traces in ascending order
> z=[sort(kn2)];
>
> z should always be even number of samples, how to get it ..i some time get them odd

Sorry, can you explain the problem a little more clearly?
You take the first N*percent samples out of N.
Why would that always be even?

Subject: Generate random sample

From: kk KKsingh

Date: 5 Mar, 2010 22:39:06

Message: 3 of 5

In the my algorithm i always need some odd number other wise my algorithm gives me error later....if z is even like suppose if z is 7 i want it to become 8 or 6.....it will ease my algorithm......And with below mention algorithm it gives me odd most of time

kn1=randperm(N);
% Randomly eliminating some samples
percent=.70 %70 percent
kn2=kn1(1:ceil(percent*N));
% sorting random chosen sampless in ascending order
z=[sort(kn2)];


"nanren888 " <nanren888.remove.this@hotmail.com> wrote in message <hmru5a$1do$1@fred.mathworks.com>...
> "kk KKsingh" <akikumar1983@gmail.com> wrote in message <hmrs1o$jhb$1@fred.mathworks.com>...
> > Generate a random sample..from N samples and it should be even always, what should i add it i dont wana use loop thinng
> >
> > kn1=randperm(N);
> > % Randomly eliminating some samples
> > percent=.70 %70 percent
> > kn2=kn1(1:ceil(percent*N));
> > % sorting random chosen traces in ascending order
> > z=[sort(kn2)];
> >
> > z should always be even number of samples, how to get it ..i some time get them odd
>
> Sorry, can you explain the problem a little more clearly?
> You take the first N*percent samples out of N.
> Why would that always be even?

Subject: Generate random sample

From: Nathan

Date: 5 Mar, 2010 22:48:46

Message: 4 of 5

On Mar 5, 2:39 pm, "kk KKsingh" <akikumar1...@gmail.com> wrote:
> In the my algorithm i always need some odd number other wise my algorithm gives me error later....if z is even like suppose if z is 7 i want it to become 8 or 6.....it will ease my algorithm......And with below mention algorithm it gives me odd most of time
>
> kn1=randperm(N);
> % Randomly eliminating some samples
> percent=.70 %70 percent
> kn2=kn1(1:ceil(percent*N));
> % sorting random chosen sampless in ascending order
> z=[sort(kn2)];
>
> "nanren888 " <nanren888.remove.t...@hotmail.com> wrote in message <hmru5a$1d...@fred.mathworks.com>...
> > "kk KKsingh" <akikumar1...@gmail.com> wrote in message <hmrs1o$jh...@fred.mathworks.com>...
> > > Generate a random sample..from N samples and it should be even always, what should i add it i dont wana use loop thinng
>
> > > kn1=randperm(N);
> > > % Randomly eliminating some samples
> > > percent=.70 %70 percent
> > > kn2=kn1(1:ceil(percent*N));
> > > % sorting random chosen traces in ascending order
> > > z=[sort(kn2)];
>
> > > z should always be even number of samples, how to get it ..i some time get them odd
>
> > Sorry, can you explain the problem a little more clearly?
> > You take the first N*percent samples out of N.
> > Why would that always be even?
>
>

One way to force z to be of even length:

kn1=randperm(N);
% Randomly eliminating some samples
percent=.70; %70 percent
%%%%
kn2=kn1(1:(2*ceil(percent*N./2)));
%%%%
% sorting random chosen sampless in ascending order
z=[sort(kn2)];

Subject: Generate random sample

From: Walter Roberson

Date: 5 Mar, 2010 22:53:39

Message: 5 of 5

kk KKsingh wrote:
> Generate a random sample..from N samples and it should be even always,
> what should i add it i dont wana use loop thinng
>
> kn1=randperm(N);
> % Randomly eliminating some samples
> percent=.70 %70 percent
> kn2=kn1(1:ceil(percent*N));
> % sorting random chosen traces in ascending order
> z=[sort(kn2)];
>
> z should always be even number of samples, how to get it ..i some time
> get them odd

kn2 = kn1(1:ceil(percent*N/2)*2);

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us