Clear Filters
Clear Filters

how can we measure X value inside for loop ?

1 view (last 30 days)
omar th
omar th on 18 Dec 2022
Edited: Voss on 20 Dec 2022
According to my code, the object that located at position A [-50; 50], I want to move it from position A to position B and let it return to A . So, I want to calculate X value at position B. But the problem, I couldn't measure X at B. My question is that, how can I let the point measure its X value at each position that reach it.
Thanks in advance.
oldPosition = [-50; 50]; % Position A
Velocity = 2 % Velocity of object
angleoption = [-14.3239 -7.1620 -4.7746 1.4324 1.5915 1.7905 7.1620 14.3239]; % turning angles of object
for ii=1:numel(angleoption)
pickangle11 = angleoption(ii) % select angle
mydir = [cos(pickangle11(:)) .* Velocity ,sin(pickangle11(:)) .* Velocity]; % rotated displacement
newPosition = oldPosition + mydir % position B
startPosition = newPosition - mydir % again return to the original position A
X(ii)=random value % just an example...means at each direction the object at
% A position is 10 and at B is ? here when its move from A to B I got 10
% or the same value at A for all directions and positions that
% reached.
% MEANS X VALUE DOESN'T MEASURED AT THE NEW POSIOTIONS.
end

Answers (1)

Voss
Voss on 18 Dec 2022
oldPosition = [-50; 50]; % Position A
Velocity = 2 % Velocity of object
Velocity = 2
angleoption = [-14.3239 -7.1620 -4.7746 1.4324 1.5915 1.7905 7.1620 14.3239]; % turning angles of object
points_to_plot = [oldPosition zeros(2,numel(angleoption))];
for ii=1:numel(angleoption)
pickangle11 = angleoption(ii) % select angle
mydir = [cosd(pickangle11(:)) .* Velocity; sind(pickangle11(:)) .* Velocity]; % rotated displacement
newPosition = oldPosition + mydir; % position B
% startPosition = newPosition - mydir % again return to the original position A
oldPosition = newPosition;
points_to_plot(:,ii+1) = newPosition;
end
pickangle11 = -14.3239
pickangle11 = -7.1620
pickangle11 = -4.7746
pickangle11 = 1.4324
pickangle11 = 1.5915
pickangle11 = 1.7905
pickangle11 = 7.1620
pickangle11 = 14.3239
plot(points_to_plot(1,:),points_to_plot(2,:),'o-')
axis equal
  2 Comments
omar th
omar th on 19 Dec 2022
First, thank you for your reply. But I already plotted the new locations for each angle option, but I wanted to measure the X value at each point (new position)
Voss
Voss on 20 Dec 2022
Edited: Voss on 20 Dec 2022
If each new point is a length-2 vector, say "P", then the x-coordinate of that point is P(1).

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!