how can we measure X value inside for loop ?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Voss
2022년 12월 18일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Filter Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!