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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Muruganandham Subramanian
on 18 Jan 2012

Hi,

Am having a incremental column matrix like, e.g. for 1st iteration, it is 100*1(double), then for 2nd iteration iteration, it will be 100*2(double), etc.. Form this, for 1st iteration, i need to get a random no (single data only). from 1st column of matrix and for 2nd iteration, i have to get a random no. from 2nd column of matrix only.

Thank you in advance!!@!!

*No products are associated with this question.*

Answer by Wayne King
on 18 Jan 2012

You can use

x = randperm(100); randomindex = x(1);

Then, use that index to choose an element from the appropriate column, say your data matrix is X

X(randomindex,1) %choose from first column X(randomindex,2) %choose from 2nd column

Show 4 older comments

Muruganandham Subramanian
on 20 Jan 2012

Hi walter,

It's not working.

am having both negative and non-negative integers of 100*1, In this i have to pick single data randomly.

Walter Roberson
on 20 Jan 2012

Sorry, the references to size(X,2) should have been size(X,1)

rchoices = randperm(size(X,1));

randchoice = X(rchoices(1),IterationNumber);

## 1 Comment

## Michael

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/26415#comment_58227

Maybe I misunderstand but to me this question appears contradictory. How is a number random if it depends on your column as an input?