I deployed an object, this object moves from point to point after testing all direction via inner loop, that object chooses the direction that produce maximum value.
My question in the second iteration how can I let the New position (new_max_1 ) be as original position and in the third iteration again the new position be original position and son on.
EXAMPLE, if the original position of the deployed object is [50 -50 ] after testing three angles we found the angle =45 produced maxvalue so that object will select the position with angle=45 which is represents the new_max_1 position, Now in the second Iteration I want the object start from the new position or consider the new_max_1 as original in this equation newPos_1(i,:) =oldPos_1 + dispacement(i,:), in the second or third iteration and so on I want replace the oldPos_1 in new_max_1. Please have a look at the attached code
thanks in advance for any help
for i_1=1:1:numel(angles)
displacement(i,:) = [cos(theta_1) .* v1 ,sin(theta_1) .* v1];
newPos_1(i,:) =oldPos_1 + dispacement(i,:)
Value_1(i_1) = some calculation depends on the location of that deployed object
[maxuValue_1(countmax), idx_max1] = max(Value_1(:));
angle_produceMaxVlue = angles(idx_max1);
displacement(bestPos_1) = [cos(angle_produceMaxVlue) .* v1 ,sin(angle_produceMaxVlue) .* v1];
new_max_1(bestPos_1) = old+ displacement(bestPos_1)