필터 지우기
필터 지우기

How can I define the time steps of an x-y plot?

조회 수: 7 (최근 30일)
Vladimir Palukov
Vladimir Palukov 2019년 7월 6일
댓글: infinity 2019년 7월 7일
Hi! I'm trying to make a script, which plots this equations.
my code so far:
clc;clear;
t=0 % Time
tend=0.40 % end time
dt=0.01; % Time step
f=200; % Frequency in Hz
vs=100; %Velocity in x in mm/s
A1=1.2; %Amplitude in y-direction
A2=0.6; %Amplitude in x-dirction
for t=0:dt:tend;
X=vs*t+A1*sin(2*pi*f*t);
Y=A2*sin(2*pi*f*t+pi/2);
plot (X, Y,'-b')
end
How can I define my time steps so that I get the same plot like like the one from the link? There is sth wrong with my time step.
Thnaks in advance

채택된 답변

infinity
infinity 2019년 7월 6일
Hello,
To get the same figure, you should refine the time step and then you should store value of X and Y with respect to t before you plot them. For example, some lines below will give the same figure
clc;
clear;
close all
tend=0.40; % end time
dt=0.0001; % Time step
f=200; % Frequency in Hz
vs=100; %Velocity in x in mm/s
A1=1.2; %Amplitude in y-direction
A2=0.6; %Amplitude in x-dirction
t = 0:dt:tend;
X=vs*t+A1*sin(2*pi*f*t);
Y=A2*sin(2*pi*f*t+pi/2);
plot(X,Y,'-b')
xlabel('x')
ylabel('y')
% for t=0:dt:tend
% X(i)=vs*t+A1*sin(2*pi*f*t);
% Y(i)=A2*sin(2*pi*f*t+pi/2);
% plot (X, Y,'-b')
% hold on
% end

추가 답변 (1개)

Vladimir Palukov
Vladimir Palukov 2019년 7월 7일
Thanks for the reply :)
Is it possible to use some form of for loop or sth to add the real time movement ot the oscillation? This is why I put the plot inside the loop on first place
  댓글 수: 1
infinity
infinity 2019년 7월 7일
Yes,
You can put the data X, Y inside the loop like this
clc;
clear;
close all
tend=0.40; % end time
dt=0.0005; % Time step
f=200; % Frequency in Hz
vs=100; %Velocity in x in mm/s
A1=1.2; %Amplitude in y-direction
A2=0.6; %Amplitude in x-dirction
t = 0:dt:tend;
X=vs*t+A1*sin(2*pi*f*t);
Y=A2*sin(2*pi*f*t+pi/2);
figure
for i = 1:1:length(t)-1
plot(X(1,i:i+1),Y(1,i:i+1),'-*b')
hold on
xlabel('x')
ylabel('y')
pause(1)
end
hold off
It will give you the movement of X, Y during the time.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by