MATLAB- graphing time versus velocity

New to MATLAB here. Trying to graph time versus velocity for something going down an incline ramp. Everything seems to work okay up until I get my graph. I want an increasing line showing 10 intervals, but it just shows a single dot in the middle of the graph. Does anyone see what I'm doing wrong? Any help is appreciated!
% A cart is rolling down a frictionless inclined plane
% Prompt user for ramp length
S=input('What is the ramp length? ');
% Prompt user for ramp incline
theta=input('What is the degree of the ramp incline? ');
% Calculation for acceleration(a) with g as a constant =9.81
% Formula for acceleration is a=gsind(theta)
a=9.81*sind(theta);
Acceleration=a
% Solved for Time (t)
t=((2*S)/a)*0.5;
Time=t
% Calculate velocity
v=S/t;
Velocity=v
% Graph to show velocity of cart at 10 intervals
T=0:t/10:t;
y=v
x=t
plot(x,y,'-.dr');
xlabel('Time')
ylabel('Velocity')
title('Velocity vs Time of cart rolling down ramp')

답변 (1개)

Star Strider
Star Strider 2015년 9월 18일

0 개 추천

I took some liberties with your code, however the problem is that you are defining only one value of ‘t’ and one value of ‘v’. You need to use the vector ‘T’. This produces the sort of plot you want:
T=0:t/10:t;
y=a*T;
x=T;
plot(x,y,'-.dr');

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

질문:

2015년 9월 18일

답변:

2015년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by