Random data selection from a matrix

1 view (last 30 days)
How can i select 5 datasample from the matrix
Z=[43;-57;98;23;-13;243;-98;112;325;560]

Accepted Answer

Image Analyst
Image Analyst on 8 Mar 2014
Try this:
Z=[43;-57;98;23;-13;243;-98;112;325;560]
elementsToExtract = randperm(numel(Z), 5)
z5 = Z(elementsToExtract)
  3 Comments
Image Analyst
Image Analyst on 8 Mar 2014
You must have a really old version of MATLAB. What version/release do you have? You can extract the 5 yourself:
Z=[43;-57;98;23;-13;243;-98;112;325;560]
elementsToExtract = randperm(numel(Z))
z5 = Z(elementsToExtract(1:5))
Tinkul
Tinkul on 8 Mar 2014
Thanx sir. Now its working...I have matlab 7.8.0(R2009a) version...

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!