How to plot time against acceleration in my code?

Hi! I'm new to Matlab and trying to understand the basics, but I've run into a problem. I have imported data from an excel sheet about the trajectory of a small marble, but when I try the plot acceleration (ax or ay) against the time (t), all values of ax and ay are plotted against one t value! I assume this problem emerges because I am using diff(vx) to differentiate my velocity functions... How can I change my code in order to plot these values against their corresponding ts? Thanks in advance!
x=xlsread('marble excel.xlsx','B2:B26');
y=xlsread('marble excel.xlsx','C2:C26');
t=xlsread('marble excel.xlsx','A2:A26');
vx=x/t;
vy=y/t;
ax=diff(vx);
ay=diff(vy);
plot(t,ax)
hold
plot(t,ay)

 채택된 답변

Image Analyst
Image Analyst 2015년 2월 22일
편집: Image Analyst 2015년 2월 22일

0 개 추천

You need an element-by-element divide, not a matrix divide:
vx = x ./ t;
vy = y ./ t;
plot(t(1:end-1),ax)
hold all;
plot(t(1:end-1),ay)

댓글 수: 2

thanks! Just one question though: why is t(1:end-1) required instead of t(1:end)? I tried that as well, but a vector length error appears.
When you do diff(), you get a vector one shorter than what you started with.

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

추가 답변 (1개)

Vinayak
Vinayak 2025년 4월 1일

0 개 추천

x=xlsread('marble excel.xlsx','B2:B26');
y=xlsread('marble excel.xlsx','C2:C26');
t=xlsread('marble excel.xlsx','A2:A26');
vx=x/t;
vy=y/t;
ax=diff(vx);
ay=diff(vy);
plot(t,ax)
hold
plot(t,ay)

카테고리

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

태그

질문:

2015년 2월 22일

답변:

2025년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by