Sign in

username:

password:



Not a member?

Search matlab



Search tips

Subscribe to matlab



matlab by Keywords

Atanh | Autocorrelation | Bandpass Filter | C++ | Conv | Database | Deconv | Excel | FFT | Filter | Filtering | FIR | Fourier Transfrom | FSK | Gaussian Noise | Haykin | IFFT | Image | Java | LFSR | LMS | LPC | MEX | OFDM | QPSK | Radix | Random | Sampling | Segmentation | Simulink | Visual Basic | Waveform | Wavelet

Ads

Discussion Groups

Discussion Groups | Matlab DSP | random row sampling

Technical discussion about Matlab and issues related to Digital Signal Processing.

  

Post a new Thread

random row sampling - Cagin Kandemir Cavas - May 27 6:32:08 2008



Hi all,
 
Suppose I have a matrix X as follows,
 
     2     3     4     1     8     7     6     2     1     2     5     7     4     7     2    
3
 
Then how should I write a code to sample two row ramdomly (called Y) from that matrix. At last,
I must have two matrix; X matrix must become 2x4 (with remaining row after sampling) and Y
matrix (2x4). Please help me as soon as possible. Thanks in advance,
------------------------------------



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: random row sampling - arkkimede - May 27 11:50:42 2008

Your question can break in two part.
1) Make a sample random is equivalent to make a permutation of the vector
2) You can reshape the vector in two colums

Example:

% The number of elements must be even
x = [2 4 7 9 4 3 6 8 4 7];
N = length(x)
new_index = randperm(N);

y = x(new_index);

newy = reshape(y,2,N/2);

On Tue, May 27, 2008 at 10:12 AM, Cagin Kandemir Cavas <
c...@hotmail.com> wrote:

> Hi all,
>
> Suppose I have a matrix X as follows,
>
>     2     3     4     1     8     7     6     2     1     2     5     7
> 4     7     2     3
>
> Then how should I write a code to sample two row ramdomly (called Y) from
> that matrix. At last, I must have two matrix; X matrix must become 2x4 (with
> remaining row after sampling) and Y matrix (2x4). Please help me as soon as
> possible. Thanks in advance,
>



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: random row sampling - Felipe Giraldo - May 27 12:24:25 2008

Try this:

X = [2&nbsp; &nbsp;&nbsp;&nbsp;3&nbsp;
&nbsp;&nbsp;&nbsp;4&nbsp; &nbsp;&nbsp;&nbsp;1;
&nbsp;&nbsp; &nbsp; &nbsp; 8&nbsp;
&nbsp;&nbsp;&nbsp;7&nbsp; &nbsp;&nbsp;&nbsp;6&nbsp;
&nbsp;&nbsp;&nbsp;2;
&nbsp; &nbsp; &nbsp;&nbsp; 1&nbsp;
&nbsp;&nbsp;&nbsp;2&nbsp; &nbsp;&nbsp;&nbsp;5&nbsp;
&nbsp;&nbsp;&nbsp;7;
&nbsp; &nbsp; &nbsp;&nbsp; 4&nbsp;
&nbsp;&nbsp;&nbsp;7&nbsp; &nbsp;&nbsp;&nbsp;2&nbsp;
&nbsp;&nbsp;&nbsp;3];

random_index = randperm(4);&nbsp;&nbsp;&nbsp; % &gt;&gt; help randperm
Y1 = X(random_index(1:2), : );
Y2 = X(random_index(3:4), : );

Best regards,

LF
--- El mar 27-may-08, Cagin Kandemir Cavas &lt;c...@hotmail.com&gt; escribió:
De: Cagin Kandemir Cavas &lt;c...@hotmail.com&gt;
Asunto: [matlab] random row sampling
A: m...@yahoogroups.com
Fecha: martes, 27 mayo, 2008, 3:12 am

Hi all,
 
Suppose I have a matrix X as follows,
 
     2     3     4     1     8     7     6     2     1     2     5     7     4 
   7     2     3
 
Then how should I write a code to sample two row ramdomly (called Y) from that
matrix. At last, I must have two matrix; X matrix must become 2x4 (with
remaining row after sampling) and Y matrix (2x4). Please help me as soon as
possible. Thanks in advance,


(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )