Worst-case linear-time order statistics Selecting

3 ビュー (過去 30 日間)
Ege Alp TURKYENER
Ege Alp TURKYENER 2019 年 11 月 3 日
コメント済み: Dheeraj Singh 2019 年 11 月 14 日
Hi.Ihave a some problem with solving this algorithm. Question is:
1) the n elements into groups of 5. Find the median of each 5-element group by rote.
so ı wrote this code. But how ı can select the numbers from array and add create new groups of 5 elements ?
a = randperm(100,21) ;
disp(a);
len_a = length(a);
mod_a = mod(len_a,5);
b = ceil(len_a /5);
disp(b);
for j=1:b
gj = zeros(b,1);
end
for j = 1:5
gj(j,1) = a(1,j);
end

回答 (1 件)

Dheeraj Singh
Dheeraj Singh 2019 年 11 月 8 日
You can simply do something like this:
array=randperm(100,21)
noOfGroups=ceil(numel(array)/5);
medianGroup=zeros(noOfGroups,1);
for i=1:noOfGroups
group=array((i-1)*5+1:min(i*5,numel(array)));
%find median of the group
medianGroup(i)=findMedian(group)
end
  2 件のコメント
Ege Alp TURKYENER
Ege Alp TURKYENER 2019 年 11 月 10 日
function pivot = rand_partition_old(array)
noOfGroups=ceil(numel(array)/5);
medianGroup=zeros(noOfGroups,1);
for i=1:noOfGroups
group=array((i-1)*5+1:min(i*5,numel(array)));
%find median of the group
medianGroup(i)=median(group);
end
pivot = medianGroup;
ı changed your code to this but ı have still a problem saying;
Out of memory. The likely cause is an infinite recursion within the program.
Error in rand_partition_old (line 11)
medianGroup(i)=median(group);
Dheeraj Singh
Dheeraj Singh 2019 年 11 月 14 日
i don't see any recursive code here...
can you provide the array as a mat file

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by