How can I let random point to START from the selected location in each iteration in FOR LOOP ?

4 ビュー (過去 30 日間)
omar th
omar th 2022 年 12 月 30 日
コメント済み: Jan 2022 年 12 月 30 日
The code below deploy random point and make it move in 5 directions. So, after excuting the first loop, the second loop will select the direction that produce max " X " value. My question is, How can Iet this random point to start from the position that selected when produce max " X " value IN THE SECOND ITERATION AND THIRD ITERATION UP TO 10 iterations that determined in the third loop. In other words how can I let the point to START from selected position each iteration ?
Thanks in advance
v=2;%7.2/3.6;
hfig = figure('Color', 'w');
hax = axes('Parent', hfig);
for gg = 1:1:10 % THIRD LOOP
for jj=1:1 % SECOND LOOP
angleOption = [24 56 72 36 96];
for ii = 1:numel(angleOption) % FIRST LOOP
chooseAngle = angleOption(ii)
PosPoint1_x=center(1)+cos(chooseAngle); % Initial positions
PosPoint1_y=center(2)+sin(chooseAngle);
PosPoint1 = [PosPoint1_x ,PosPoint1_y]
h(1) = plot(PosPoint1(1,1),PosPoint1(1,2),'Parent', hax,'Marker', '.','Color', 'k','LineStyle', '-','MarkerSize', 12);
hold(hax, 'on')
grid(hax, 'on')
axis(hax, 'equal')
displacement = [cos(chooseAngle).*v, sin(chooseAngle).*v];
newPos = PosPoint1 + displacement
startpos = newPos-displacement
dd(ii,:)=newPos(:,:)
cc=length(dd)
dd1(ii,:)=startpos(:,:)
cc1=length(dd1)
XData = [h.XData PosPoint1(:, 1)];
YData = [h.YData PosPoint1(:, 2)];
set(h, 'XData', XData, 'YData', YData)
drawnow
XData = [h.XData PosPoint1(:, 1)];
YData = [h.YData PosPoint1(:, 2)];
set(h, 'XData', XData, 'YData', YData)
drawnow
% currentXvalue_1(ii) = DO SOME CALCULATIONS
end
[maxXvalue_1(countmax), idx_max1] = max(currentXvalue_1);
pickangle_maxX_1 = ActionSpace11(idx_max1)
Displacement_max1 = [cos(pickangle_maxX_1(:)) .* v1 ,sin(pickangle_maxX_1(:)) .* v1];
XYnew11Max = PosPoint1 + Displacement_max1;
%XYnew11Max= startPosition(end);
fprintf(' 1 Keep on the same position ');
XData = [h(1).XData PosPoint1(:,1)];
YData = [h(1).YData PosPoint1(:,2)];
set(h(1), 'XData', XData, 'YData', YData)
drawnow
end
end
  1 件のコメント
Jan
Jan 2022 年 12 月 30 日
Which of the variable is "the random point"? Which part of the code is relevant for the question?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by