フィルターのクリア

Info

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

could anyone tell me how to modify the line without using randsample

2 ビュー (過去 30 日間)
Prabha Kumaresan
Prabha Kumaresan 2018 年 3 月 20 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
code:
unused_rows=1:12;
N_UE_rows=2;
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
If i remove randsample in the above line such that rows=unused_rows(length(unused_rows),N_UE_rows) i am getting error
Attempted to access unused_rows(12,2); index out of bounds because size(unused_rows)=[1,12].
could anyone help me to fix it.
  4 件のコメント
Rik
Rik 2018 年 3 月 20 日
The number of rows is fixed. The specific rows are not. Is that what you want?
Prabha Kumaresan
Prabha Kumaresan 2018 年 3 月 20 日
the number of rows and the specific rows in the number of rows as well.

回答 (1 件)

Jan
Jan 2018 年 3 月 20 日
unused_rows = 1:12;
N_UE_rows = 2;
rows = unused_rows(randperm(length(unused_rows), N_UE_rows));
This chooses 2 random values from the vector unused_rows.
  2 件のコメント
Prabha Kumaresan
Prabha Kumaresan 2018 年 3 月 20 日
if i use randperm only two random values are chosen. but what i actually need is i need to choose all the 12 values such that each group should contain 2.If i run the code next time the same value needs to be selected.
Jan
Jan 2018 年 3 月 20 日
@Prabha: Your question was to write the code without randsample. Now you are asking a different question.
This creates a matrix containing the numbers 1 to 12, where the rows contains two different elements:
reshape(randperm(12), 6, 2)
When I see your other question https://www.mathworks.com/matlabcentral/answers/389430-could-anyone-help-me-how-to-fix-this-issue, it seems, like you want something else.
You have asked 188 questions already and the thread about "How to ask a good question" has been suggested repeatedly. Again: Please care for asking a clear question.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by