필터 지우기
필터 지우기

Matlab animation for x y plot that varies with time.

조회 수: 42 (최근 30일)
friet
friet 2016년 10월 15일
답변: Walter Roberson 2016년 10월 15일
Hello, I have a simple function that varies with time. The function is y=mx however, m varies with time. at 10 sec it is 3 and at 20 sec it is 5. I want to have animation xy plot that shows how xy plot varies with time. How can I put a clock at the top of the graph that shows the time? This is the code I tried.
clear all
clc
x = 0:10:(100);
%at 10 sed
y=3*x;
%at 20 sed
y=5*x;
%at 50 sed
y=7*x;
slope=[3 5 7]
for k=1:3
y(k,:)=slope(k)*x;
end
for i=1:3
hold all
plot(x,y(i,:))
pause(0.5)
%
end
Any help is appreciated.
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 15일
slope_times = [0, 10, 20, 50];
slope = [1, 3, 5, 7]; %you need to recheck the initial slope
x = 0:10:100;
times = linspace(slope_times(1), slope_times(end));
m = interp1(slope_times, slope, times);
for k = 1 : length(times)
y = m(k) * x;
plot(x, y);
title( sprintf('t = %.1f', times(k)) );
hold all
pause( 0.5 );
end
hold off

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by