How to change the rng value
5 次查看(过去 30 天)
显示 更早的评论
code:
unused_rows=1:6
while ~isempty(unused_rows)
N_UE_rows=2;
rng(3)
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
The above code works how to run the code by having different numbers of rng say for example rng(12),rng(2),rng(1).
1 个评论
Steven Lord
2018-5-1
Prabha, you've asked this same question or a slight variation several times now. It's still not clear to me exactly what you're trying to do. Please take a short break from coding and write out IN WORDS NOT CODE a description of what you're trying to do. Explain it as though you were explaining it to someone who has no idea what problem you're trying to solve. That may help us understand your ultimate goal and allow us to suggest more effective solutions to that problem.
采纳的回答
Walter Roberson
2018-3-21
list_of_rng_seeds = [12, 2, 1];
rng_usage_idx = 0;
unused_rows = 1:6;
while ~isempty(unused_rows)
N_UE_rows = 2;
rng_usage_idx = mod(rng_usage_idx, length(list_of_rng_seeds)) + 1;
rng(rng_usage_idx);
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
28 个评论
Prabha Kumaresan
2018-3-21
but i can view the result for one rng value how to view the result for rng=2,rng=3,rng=12 .
Prabha Kumaresan
2018-3-21
could you help me how to use the rng values in for loop so that for each run different values of rng can be used.
Steven Lord
2018-3-21
Why are you resetting the random number generator in each iteration of your while loop? Are you doing so to compare the results that you receive from those specific seeds? Or are you doing so because you think that makes it "more random"? In the latter case, the recommendation is to NOT reset the generator.
Walter Roberson
2018-3-23
list_of_rng_seeds = [12, 2, 1];
num_rng = length(list_of_rng_seeds);
for rng_usage_idx = 1 : num_rng
this_seed = list_of_rng_seeds(rng_usage_idx);
fprintf('Below results are for rng = %d\n', this_seed);
rng(this_seed);
unused_rows = 1:6;
while ~isempty(unused_rows)
N_UE_rows = 2;
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
end
Prabha Kumaresan
2018-3-23
thanks now i can get the output for list of rng seeds. could you help me how to combine the rows of 12,2,1 separately,as i need to calculate the throughput value of 12,2,1.
Walter Roberson
2018-3-23
Your code has no output as such. You overwrite all of your variables for each iteration of the loop. The only reason to execute your code is to display the results to the screen.
Prabha Kumaresan
2018-3-28
编辑:Walter Roberson
2018-3-28
I would like to check with you the following code
list_of_rng_seeds = [12, 2, 1]; num_rng = length(list_of_rng_seeds); for rng_usage_idx = 1 : num_rng this_seed = list_of_rng_seeds(rng_usage_idx); fprintf('Below results are for rng = %d\n', this_seed); rng(this_seed); unused_rows = 1:6; while ~isempty(unused_rows) N_UE_rows = 2; rows=unused_rows(randsample(length(unused_rows),N_UE_rows)) [~,idx]=find(ismember(unused_rows,rows)) unused_rows(idx)=[] end end
In the code the number of rows for each rng is getting fixed, say for example for rng=1 ,(34) and (12) form groups. I would like to check how to have variable numbers such that (3),(2),and (14) for rng.
Walter Roberson
2018-3-28
I am not sure why you say that for rng 1, that (34) and (12) form groups? Did you mean (36) and (12) ? See below.
"I would like to check how to have variable numbers such that (3),(2),and (14) for rng"
I am not sure what you are asking, but I suspect what you are referring to is that the number of rows obtained at first is always 2. That is because you assigned N_UE_rows = 2 instead of determining the number of rows randomly. If I recall correctly, somewhere around your 171's question in Answers you were randomly determining the number of rows selected -- back then it was just a matter that the way you were selecting, it was lower probability that N_UE_rows would be well distributed.
Below results are for rng = 1
rows =
3 6
idx =
3 6
unused_rows =
1 2 4 5
rows =
1 2
idx =
1 2
unused_rows =
4 5
rows =
4 5
idx =
1 2
Prabha Kumaresan
2018-4-5
编辑:Walter Roberson
2018-4-5
i would like to check the following code:
list_of_rng_seeds = [12, 2, 1];
num_rng = length(list_of_rng_seeds);
for rng_usage_idx = 1 : num_rng
this_seed = list_of_rng_seeds(rng_usage_idx);
fprintf('Below results are for rng = %d\n', this_seed);
rng(this_seed);
unused_rows = 1:6;
while ~isempty(unused_rows)
N_UE_rows = 2;
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
end
could you please help me to run the above code with respect to different list_of_rng_seeds=[3 4 5 6 7],[8 9 10 11 12 13].
Walter Roberson
2018-4-5
lists_of_rng_seeds = {[12, 2, 1], [3 4 5 6 7],[8 9 10 11 12 13]};
for seed_idx = 1 : length(lists_of_rng_seeds)
list_of_rng_seed = lists_of_rng_seeds{seed_idx};
num_rng = length(list_of_rng_seeds);
for rng_usage_idx = 1 : num_rng
this_seed = list_of_rng_seeds(rng_usage_idx);
fprintf('Below results are for rng = %d\n', this_seed);
rng(this_seed);
unused_rows = 1:6;
while ~isempty(unused_rows)
N_UE_rows = 2;
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
end
end
Prabha Kumaresan
2018-4-5
I am getting Error using fprintf Function is not defined for 'cell' inputs. Error in line fprintf('Below results are for rng = %d\n', this_seed);
Could you help me to overcome it.
Walter Roberson
2018-4-5
list_of_list_of_seeds = {[12, 2, 1], [3 4 5 6 7],[8 9 10 11 12 13]};
for seed_idx = 1 : length(list_of_list_of_seeds)
list_of_rng_seeds = list_of_list_of_seeds{seed_idx};
num_rng = length(list_of_rng_seeds);
for rng_usage_idx = 1 : num_rng
this_seed = list_of_rng_seeds(rng_usage_idx);
fprintf('Below results are for rng = %d\n', this_seed);
rng(this_seed);
unused_rows = 1:6;
while ~isempty(unused_rows)
N_UE_rows = 2;
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
end
end
Prabha Kumaresan
2018-4-5
编辑:Walter Roberson
2018-4-5
I also want to use include the command
N_UE_rows=ceil(sqrt(randi([2,numel(unused_rows)])));
N_UE_rows=ceil(sqrt(randi([numel(unused_rows)])));
in addition to
N_UE_rows = 2;
such that [12, 2, 1] make use of
N_UE_rows = 2;
[3 4 5 6 7] need to use
N_UE_rows=ceil(sqrt(randi([2,numel(unused_rows)])));
and [8 9 10 11 12 13] need to use
N_UE_rows=ceil(sqrt(randi([numel(unused_rows)])));
could you please help me on this.
Walter Roberson
2018-4-5
determine_N_UE_rows{1} = @(unused_rows) 2;
determine_N_UE_rows{2} = @(unused_rows) ceil(sqrt(randi([2,numel(unused_rows)])));
determine_N_UE_rows{3} = @(unused_rows) N_UE_rows=ceil(sqrt(randi([numel(unused_rows)])));
list_of_list_of_seeds = {[12, 2, 1], [3 4 5 6 7],[8 9 10 11 12 13]};
for seed_idx = 1 : length(list_of_list_of_seeds)
list_of_rng_seeds = list_of_list_of_seeds{seed_idx};
N_UE_rows_fun = determine_N_UE_rows{seed_idx};
num_rng = length(list_of_rng_seeds);
for rng_usage_idx = 1 : num_rng
this_seed = list_of_rng_seeds(rng_usage_idx);
fprintf('Below results are for rng = %d\n', this_seed);
rng(this_seed);
unused_rows = 1:6;
while ~isempty(unused_rows)
N_UE_rows = N_UE_rows_fun(unused_rows);
rows = unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
end
end
Prabha Kumaresan
2018-4-5
编辑:Prabha Kumaresan
2018-4-9
could you please help me to include list_of_list_of_seeds to calculate the throughput and run with different iterations with respect to the following command line
output1(t,r)=overall_throughput1;
output1_it(t,r,it)=output1(t,r);
where t=6 and r=8.
I want to include list_of_list_of_seeds with respect to the above command line.
Could you please help me on this.
Prabha Kumaresan
2018-4-6
Could you please help me how to calculate the throughput for [12, 2, 1],[3 4 5 6 7],[8 9 10 11 12 13] separately as i need to plot the graph for each throughput in one graph.
I tried with the code given to calculate the throughput followed by plotting the graph.
determine_N_UE_rows{1} = @(unused_rows) 2;
determine_N_UE_rows{2} = @(unused_rows) ceil(sqrt(randi([2,numel(unused_rows)])));
determine_N_UE_rows{3} = @(unused_rows) N_UE_rows=ceil(sqrt(randi([numel(unused_rows)])));
list_of_list_of_seeds = {[12, 2, 1], [3 4 5 6 7],[8 9 10 11 12 13]};
for seed_idx = 1 : length(list_of_list_of_seeds)
list_of_rng_seeds = list_of_list_of_seeds{seed_idx};
N_UE_rows_fun = determine_N_UE_rows{seed_idx};
num_rng = length(list_of_rng_seeds);
for rng_usage_idx = 1 : num_rng
this_seed = list_of_rng_seeds(rng_usage_idx);
fprintf('Below results are for rng = %d\n', this_seed);
rng(this_seed);
unused_rows = 1:6;
while ~isempty(unused_rows)
N_UE_rows = N_UE_rows_fun(unused_rows);
rows = unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
end
end
throughput=........;
dummyX = 1:length(N_rng);
figure
plot(dummyX,y,'rs');
hold on;grid on;
But I am unable to get the throughput result separately.Could you please help me on this
Walter Roberson
2018-4-9
Prabha Kumaresan, you have asked over 200 questions. You have had plenty of time to learn to understand the basics of for loops.
Go heavy into cell arrays if you need to. The first rule of programming is to get it to work first and only then worry about optimizing it.
Prabha Kumaresan
2018-4-9
Ok.I have tried with the following code with respect to four iterations. output1(t,seed_idx,s,r)=overall_throughput1; output1_it(t,seed_idx,s,r,it)=output1(t,seed_idx,s,r); But the output1_it remains the same for all the iterations.Could you please help me on this.
Prabha Kumaresan
2018-5-1
with respect to the code given i want to include some commands onto it.
N_UE=[4 6 8]
for t=1:length(N_UE)
list_of_list_of_seeds = {[12, 2, 1], [3 4 5 6 7],[8 9 10 11 12 13]};
for seed_idx = 1 : length(list_of_list_of_seeds)
list_of_rng_seeds = list_of_list_of_seeds{seed_idx};
num_rng = length(list_of_rng_seeds);
for rng_usage_idx = 1 : num_rng
this_seed = list_of_rng_seeds(rng_usage_idx);
fprintf('Below results are for rng = %d\n', this_seed);
rng(this_seed);
unused_rows = 1:N_UE(t);
while ~isempty(unused_rows)
N_UE_rows = 2;
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
end
end
end
Could you please help me how to select when N_UE=4,list_of_list_of_seeds=[12,2,1] N_UE=6,list_of_list_of_seeds=[3,4,5,6,7] N_UE=8,list_of_list_of_seeds=[8,9,10,11,12,13]
Prabha Kumaresan
2018-5-2
ok. N_UE=4
the following results should be
Below results are for rng = 12
rows =
3
rows =
1 4 2
Below results are for rng = 2
rows =
1 4
rows =
2 3
Below results are for rng = 1
rows =
2 4
rows =
1 3
N_UE=6
Below results are for rng = 3
rows =
6 2
rows =
1
rows =
5
rows =
4 3
Below results are for rng = 4
rows =
5 1 4
rows =
2
rows =
3 6
Below results are for rng = 5
rows =
2 4
rows =
5 3
rows =
1 6
Below results are for rng = 6
rows =
3 4 1
rows =
2 6 5
Below results are for rng = 7
rows =
5
rows =
4 6
rows =
3 1 2
N_UE=8
the following result should be
Below results are for rng = 8
rows =
5 4 7
rows =
2 1
rows =
3 8 6
Below results are for rng = 9
rows =
5
rows =
1
rows =
3 6
rows =
7
rows =
4 2 8
Below results are for rng = 10
rows =
1 8 6
rows =
5
rows =
4
rows =
3 2 7
Below results are for rng = 11
rows =
4 1
rows =
2 8
rows =
7 5
rows =
6 3
Below results are for rng = 12
rows =
6 3
rows =
2 5 7
rows =
4 8 1
Below results are for rng = 13
rows =
1 5 6
rows =
2 4
rows =
8 3 7
Could you please help me on this.
Prabha Kumaresan
2018-5-7
编辑:Walter Roberson
2018-5-7
With respect to the code given
unused_rows=1:6
while ~isempty(unused_rows)
N_UE_rows=2;
rng(3)
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
Could you please help me how to write the algorithm for it.
Prabha Kumaresan
2018-5-7
编辑:Walter Roberson
2018-5-7
with respect to the code given
list_of_list_of_seeds = {[12, 2, 1], [3 4 5 6 7],[8 9 10 11 12 13]};
for seed_idx = 1 : length(list_of_list_of_seeds)
list_of_rng_seeds = list_of_list_of_seeds{seed_idx};
num_rng = length(list_of_rng_seeds);
for rng_usage_idx = 1 : num_rng
this_seed = list_of_rng_seeds(rng_usage_idx);
fprintf('Below results are for rng = %d\n', this_seed);
rng(this_seed);
unused_rows = 1:6;
while ~isempty(unused_rows)
N_UE_rows = 2;
rows=unused_rows(randsample(length(unused_rows),N_UE_rows))
[~,idx]=find(ismember(unused_rows,rows))
unused_rows(idx)=[]
end
end
end
could you please help me how to write the algorithm for it.
Walter Roberson
2018-5-7
I am not sure what you mean by "write the algorithm for it" ? Are you asking for something like a flow chart? Are you asking for pseudocode to write into project documentation ?
None of the people who has been volunteering to respond to your questions are able to write the pseudocode for that, because not one of us has been able to understand why you want to keep setting the random seed.
Walter Roberson
2018-5-7
Flow charts are usually fairly straight forward to write once you have the code. I find reference to a commercial tool http://www.aivosto.com/visustin.html which can generate flow charts from MATLAB. See also https://stackoverflow.com/questions/5518200/automatically-generating-a-diagram-of-function-calls-in-matlab
更多回答(0 个)
另请参阅
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)