How to plot vectors of different length

4 visualizzazioni (ultimi 30 giorni)
Sarah Hicks
Sarah Hicks il 4 Ott 2018
Risposto: Star Strider il 4 Ott 2018
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

Risposte (1)

Star Strider
Star Strider il 4 Ott 2018
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.

Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by