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:
Randsample (leave-one-out)

Subject: Randsample (leave-one-out)

From: Frank Sabouri

Date: 8 Sep, 2010 15:37:05

Message: 1 of 4

Hello,

I am going to creat this random numbers ('x'), in that one row leave out and each column is independent:
--------------------------------
x=
[1 1 1 1 2
 2 2 2 3 3
 3 3 4 4 4
 4 5 5 5 5];
---------------------------
p=zeros (4,5);
for i = 1:5
    [p(:,i)]=randsample(5,4);
end
p=sort(p);
p=
[2 1 2 2 1
 3 2 3 3 2
 4 3 4 4 3
 5 5 5 5 5];
-------------------------------
I used "randsample" to creat "x", however "p" is not equal with "x". As you can see the columns in "p" are not independent.

Please let me know if there is other function that allows me to generate "x".

Thanks,
Frank

Subject: Randsample (leave-one-out)

From: Sean

Date: 8 Sep, 2010 15:51:10

Message: 2 of 4

"Frank Sabouri" <Frank.Sabouri@gmail.com> wrote in message <i68aj1$n6r$1@fred.mathworks.com>...
> Hello,
>
> I am going to creat this random numbers ('x'), in that one row leave out and each column is independent:
> --------------------------------
> x=
> [1 1 1 1 2
> 2 2 2 3 3
> 3 3 4 4 4
> 4 5 5 5 5];
> ---------------------------
> p=zeros (4,5);
> for i = 1:5
> [p(:,i)]=randsample(5,4);
> end
> p=sort(p);
> p=
> [2 1 2 2 1
> 3 2 3 3 2
> 4 3 4 4 3
> 5 5 5 5 5];
> -------------------------------
> I used "randsample" to creat "x", however "p" is not equal with "x". As you can see the columns in "p" are not independent.
>
> Please let me know if there is other function that allows me to generate "x".
>
> Thanks,
> Frank

Like this:
reshape(repmat(1:5,4,1),5,4).'
?
%Sean

Subject: Randsample (leave-one-out)

From: Jan Simon

Date: 9 Sep, 2010 10:38:06

Message: 3 of 4

Dear Frank,

> x=
> [1 1 1 1 2
> 2 2 2 3 3
> 3 3 4 4 4
> 4 5 5 5 5];

y = transpose(nchoosek(1:5, 4));
isequal(y, x)
>> 1

For larger sizes NCHOOSEK is really slow. You could use the much faster C-Mex VChooseK:
  http://www.mathworks.com/matlabcentral/fileexchange/26190
The Combinator of Matt Fig is faster than NCHOOSEK also:
  http://www.mathworks.com/matlabcentral/fileexchange/24325

Good luck, Jan

Subject: Randsample (leave-one-out)

From: Peter Perkins

Date: 9 Sep, 2010 13:06:08

Message: 4 of 4

On 9/8/2010 11:37 AM, Frank Sabouri wrote:
> I am going to creat this random numbers ('x'), in that one row leave out
> and each column is independent:

I'm not exactly clear about what you are doing, but it's possible that
cvpartition does what you want. A small example of its use in
leave-one-out cross validation:

 >> x = 1:5;
 >> cv = cvpartition(length(x),'leaveout')
cv =
Leave-one-out cross validation partition
              N: 5
    NumTestSets: 5
      TrainSize: 4 4 4 4 4
       TestSize: 1 1 1 1 1
 >> x(training(cv,1))
ans =
      2 3 4 5
 >> x(test(cv,1))
ans =
      1

and so on. Hope this helps.

Tags for 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