how can we measure X value inside for loop ?
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Voss
on 18 Dec 2022
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
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
plot(points_to_plot(1,:),points_to_plot(2,:),'o-')
axis equal
2 Comments
See Also
Categories
Find more on Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!