which loop should I use (while loop or for loop) to find the max power for all steps from the begining to the last step for random points ?
조회 수: 2 (최근 30일)
이전 댓글 표시
first, below I deployed two random points. second i measured the power in each moving step. third I measured the max power in from each 20 moving step and this random point will re-move another 20 step moving. My question is that, can I find the max power for all moving step instead of measuring the max power for each 20 step and the measure max power for 20 step and so forth.
Thanks in advance for any help.
function UAVBSsMobilityBasedOnSINR(NumDrone, v, ro, center)
Numpoint1 = 1;center1=[0 0];center2=[0 0];
Numpoint2 = 1;ro1=1000;ro2=1000; vs1=0;vs2=0;v1=15/3.6;v2=15/3.6;
theta_point1=2*pi*(rand(Numpoint1,1)); % distributed random number of random point
g1 = 0.5 * ro1 + 0.5 * ro1 * rand(Numpoint1,1); % let the point deployed away from the center of circle network layout
Pospoint1_x=center1(1)+g1.*cos(theta_point1); % Initial positions
Pospoint1_y=center1(2)+g1.*sin(theta_point1);
Pospoint1 = [Pospoint1_x ,Pospoint1_y];
theta_point2=2*pi*(rand(Numpoint2,1)); % distributed random number of random point
g2 = 0.5 * ro2 + 0.5 * ro2 * rand(Numpoint2,1); % let the random point deployed away from the center of circle network layout
Pospoint_x=center2(1)+g2.*cos(theta_point2); % Initial positions
Pospoint2_y=center2(2)+g2.*sin(theta_point2);
Pospoint2 = [Pospoint_x ,Pospoint2_y];
hfig = figure('Color', 'w');
hax = axes('Parent', hfig);
hpoint(1) = plot(Pospoint1(1,1),Pospoint1(1,2),'Parent', hax,'Marker', '*','Color', 'k','LineStyle', 'none','MarkerSize', 12);
hold(hax, 'on')
axis(hax, 'equal')
hpoint(2) = plot(Pospoint2(1,1),Pospoint2(1,2),'Parent', hax,'Marker', '*','Color', 'r','LineStyle', 'none','MarkerSize', 12);
hold(hax, 'on')
axis(hax, 'equal')
ro=1000;center=[0 0];
t1 = linspace(0, 2*pi, 100);
plot(ro * cos(t1) + center(1), ro * sin(t1) + center(2));
Angleoption11 = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479];
Angleoption22 = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479];
alpha =2;pt=10;
currentpower1=zeros(1,1);
currentpower2=zeros(1,1);
while true
previouspower1 = currentpower1;
previouspower2 = currentpower2;
for current_index1 = 1:numel(Angleoption11)
pickangle11 = Angleoption11(current_index1);
dist_d1_d2 = sqrt((Pospoint_x-Pospoint1_x.').^2 + (Pospoint2_y-Pospoint1_y.').^2)
previouspower1 = currentpower1;
currentpower1 = pt* (dist_d1_d2)^-alpha;
[Pospoint1, pickangle11] = moveit1(Pospoint1, pickangle11, v1, ro1, center1);
fprintf(' 1 Change its Strategy ')
set(hpoint(1), 'XData', Pospoint1(1,1), 'YData', Pospoint1(1,2))
drawnow
pause(1)
end
for current_index2 = 1:numel(Angleoption22)
pickangle22 = Angleoption22(current_index2);
dist_d1_d2 = sqrt((Pospoint_x-Pospoint1_x.').^2 + (Pospoint2_y-Pospoint1_y.').^2)
currentpower2 = pt* (dist_d1_d2)^-alpha
previouspower2 = currentpower2;
[Pospoint2, pickangle22] = moveit1(Pospoint2, pickangle22, v1, ro1, center1);
fprintf(' 2 Change its Strategy ')
set(hpoint(2), 'XData', Pospoint2(1,1), 'YData', Pospoint2(1,2))
drawnow
pause(1)
end
[maxpower1, ~] = max(currentpower1);
[maxpower2, ~] = max(currentpower2);
condition1 = currentpower1 > maxpower1;
if condition1
[Pospoint1,pickangle11] = stop1(Pospoint1,pickangle11, vs1,ro1, center1);
fprintf(' P 1 ')
end
condition2 = currentpower2 > maxpower2;
if condition2
[Pospoint1,pickangle22] = stop1(Pospoint1,pickangle22, vs1,ro1, center1);
fprintf(' P 2 ')
end
cond11 = ((currentpower1-previouspower1)<0.1) && ((currentpower1-previouspower2)<0.1);
condition = condition1 & condition2 & cond11;
if condition
break
end
end
end
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!