How to plot vectors of different length

4 ビュー (過去 30 日間)
Sarah Hicks
Sarah Hicks 2018 年 10 月 4 日
回答済み: Star Strider 2018 年 10 月 4 日
We were asked to plot the derivative of angular displacement to get the angular velocity, and the derivative of angular velocity to get the angular acceleration. I was able to calculate the derivative, but it will not allow me to plot the vectors because they are not the same length. Any suggestions on how to plot?
if true
M=csvread(filename, 2,0);
a=M(:,1); %time in seconds
b=M(:,2); %angular displacement
c=M(:,3); %angular velocity
d=M(:,4); %angular acceleration
plot(a,b,'r')
hold on
plot(a,c,'g')
hold on
plot(a,d,'b')
hold on
title('Raw Kinematics Data on Arm Flexion-Extension')
%Part b
figure
l=diff(b); %differentiates the angular velocity
n=diff(c); %differentiates the angular acceleration
plot(a,l)
hold on
plot(a,n)
end

回答 (1 件)

Star Strider
Star Strider 2018 年 10 月 4 日
The problem is that you are using the numerical diff function that produces outputs that are smaller than the inputs.
A much better solution is to use the gradient (link) function instead. It produces a numeric derivative the same size as the input, eliminating the problem of different-size vectors.

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by