Hi every one. I have a moving point on the axes. How my point can move in this direction( look at picture)? Cause now it`s just moving from x 0 to x 3.6, idk what to do next

1 view (last 30 days)
  2 Comments
Daniel Ryzhuk
Daniel Ryzhuk on 12 Nov 2022
@Jan %plot(x,y)
%plot(0,0, '.','MarkerSize',10)
axes();
title('Ilmsens office')
xlabel('x-coordinate [m]')
ylabel('y-coordinate [m]')
xlim([0,3.6])
ylim([0,6.15])
view([90 -90])
hold on
% Sensor 1
%Tx1 = plot(0.2600, 0.2800,'rv','MarkerSize',6); %Tx1
%Rx1 = plot(0.1919, 0.3559,'rv','MarkerSize',6); %Rx1
%Rx2 = plot(0.3280, 0.2040,'rv','MarkerSize',6); %Rx2
% Sensor 2
%Tx2 = plot(3.3200, 0.2900,'gv','MarkerSize',6);
%Rx3 = plot(3.2450, 0.2206,'gv','MarkerSize',6);
%Rx4 = plot(3.3947, 0.3594,'gv','MarkerSize',6);
% Sensor 3
%Tx3 = plot(3.3000, 5.8600,'bv','MarkerSize',6);
%Rx5 = plot(3.3809, 5.7979,'bv','MarkerSize',6);
%Rx6 = plot(3.2190, 5.9220,'bv','MarkerSize',6);
%stepX
pmax = 1; % total no of dots
x = 0 ; %initialise the coordinates of each dots
y = 0 ;
dt = 0.25;
lifespan = 15; % life span : the total no of steps each dot has to move
for i =1:lifespan
if i == 1
for k = 1 : pmax
grid on;
hold on;
plot(x, y, 'ro-');
axis([0 3.6 0 6.15])
pause(0.4);
hold off;
end
else
h = findobj(gca,'Type', 'line');
for k = 1 : pmax
prevX = get(h(k),'XData');
%prevY = get(h(k),'YData');
set(h(k),'XData',prevX+dt)
%set(h(k),'YData',prevY+dt)
pause(0.4);
end
end
end
%stepY

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 12 Nov 2022
Edited: John D'Errico on 12 Nov 2022
You will want to do this in a parametric form. That is, think about how x moves, as a function of TIME. Don't think about y as a function of x, since it is not such a thing anyway. There is no functional relationship there.
But if you plot x(t), it would be constant for a while, then it would increase LINEARLY. then be constant for another time. You could do that using interp1. For example:
t = linspace(0,10,1000);
tbreaks = 0:1:10;
xbreaks = [0 0 1 1 2 2 3 3 4 4 5];
% think about how you could generate this sequence for longer spans. Is not
% hard. For example, could you use repmat?
x_t = interp1(tbreaks,xbreaks,t,'linear');
plot(t,x_t)
Now, you will do something similar for y_t. Even though the plot versus t might not look as you wish, when you then form the plot for x_t versus y_t, it will be correct.
Just think carefully about what the set of y values should be. As long as you were careful about how you generated ybreaks, the two curves will be exactly as you want.
ybreaks = [0 1 1 0 0 1 1 0 0 1 1];
y_t = interp1(tbreaks,ybreaks,t,'linear');
plot(x_t,y_t,'.')
This should get you started. The function animatedline might get you the rest of the way.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!