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!