Info

この質問は閉じられています。 編集または回答するには再度開いてください。

randomly picking from a series of elements

1 回表示 (過去 30 日間)
Wajdi
Wajdi 2014 年 12 月 11 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello everybody, need help to pick random elements from a series of data. Please help!
In fact I have a Matrix with three column containing 7000 lines and I want to pick only 500 lines randomly what function should I use? Thank you.
  1 件のコメント
Stalin Samuel
Stalin Samuel 2014 年 12 月 11 日
give some example

回答 (2 件)

Roger Stafford
Roger Stafford 2014 年 12 月 11 日
To avoid repetitions you can do the following. Let M be the array with 7000 rows from which you wish to select 500 at random.
M2 = M(randperm(7000,500),:);
If you want the rows to still be in the same order as they were in M, do this instead:
M2 = M(sort(randperm(7000,500)),:);

Guillaume
Guillaume 2014 年 12 月 11 日
I would use randi for this:
m = repmat((1:7000)', 1, 3); %matrix with 7000 lines, 3 columns for demo
rows = randi(size(m, 1), 1, 500); %select 500 random integers between 1 and the number of lines in m
randrows = m(rows, :); %get these rows
  2 件のコメント
Image Analyst
Image Analyst 2014 年 12 月 11 日
Wajdi's 'Answert" moved here:
Many thanks I will try this command lines. I'd like to ask if possible to read the data from excel work sheet or how can I get my data from excel?
Wajdi, unless you're giving and answer to your original question, just add a "Comment" to the person you are replying to.
Guillaume
Guillaume 2014 年 12 月 11 日
Actually, Roger is right, my answer can repeat some rows, so use (and accept) his answer.
As for the bit about excel, start a new question as it has nothing to do with the original question.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by