How to randomly select sub-sets from an array?

Hi everyone,
May someone help me ..
I have data in text file (51360 enteries) attached here. How can I select 1000 random sub-sets consists of 48 consectuive enteries.

Answers (1)

Rik
Rik on 18 Dec 2020
  1. Read your data to a Matlab variable (even load might work here).
  2. Generate a vector of 1000 integers between 1 and 51360-48. The randi function should work for you.
  3. Create a vector in the opposite direction of the one in step 2 with the values 0 to 48-1. The colon operator is enough. Mind the parentheses and use .' to flip the direction if needed.
  4. Add the two vectors together, using implicit expansion (older Matlab releases will require bsxfun(@plus,__,__) to do this).
  5. Use the resulting array to index into your loaded data. Depending on what you did in step 2 and 3, either each row or each column will be a sample.

5 Comments

Might be this approch doesn,t work in present case, my data set has 51360 entries but the maximum values is 526 and minmum value is 0. I just need help to pick 1000 random point along with 48 data points immediatly before and after these random points. The output will be an data sheet with 1000 columns and 48 rows.
Why would this not work? The values in the array itself don't matter at all if you just want to sample from them.
"48 points before and after", so you actually want 87 consecutive values from the list?
If you follow these steps you will get a 48 by 1000 array with values from your original file. Try it. If you have issues implementing one of these steps, show the code you tried and explain why it didn't do what you needed it to do.
One think is if I reverse the order this might effect the required results in negative way so it is recomended to use the data in forawrad way. Just randomly pick 1000 point and for each point there is an array of consecutive 48 data points. May you please right the code so tht i check this with manual results. Thank you
Try it. If you have issues implementing one of these steps, show the code you tried. It is not hard. You can do it. Just follow the steps I showed you. Is there any step you don't understand?
Apology for delay... I am still confused for step 2 ... I have to pick 1000 entrires randomly from the given data along with adjucemmt 48 data points. May you explain why we creat vector in one direction and then in reverse direction.

Sign in to comment.

Categories

Tags

Asked:

aa
on 18 Dec 2020

Commented:

aa
on 24 Dec 2020

Community Treasure Hunt

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

Start Hunting!