how can we measure X value inside for loop ?

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

답변 (1개)

Voss
Voss 2022년 12월 18일
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

omar th
omar th 2022년 12월 19일
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 2022년 12월 20일
편집: Voss 2022년 12월 20일
If each new point is a length-2 vector, say "P", then the x-coordinate of that point is P(1).

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

카테고리

도움말 센터File Exchange에서 Equations에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2022년 12월 18일

편집:

2022년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by