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

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

Which of the variable is "the random point"? Which part of the code is relevant for the question?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2022년 12월 30일

댓글:

Jan
2022년 12월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by