differentiate a 7000*6 matrix with a 7000*1 vector

1 次查看(过去 30 天)
Hi dear,
I am trying to differentiate a 7000*6 matrix with a 7000*1 vector. The details are:
The size of the matrix A_disp is 7000*6 containing the data of six motors' displacements,
and the size of the vector b_time is 7000*1 which is in fact the time series from 0 to 6999 seconds with an interval 1s.
Now I want to get the velocities of the six motors.
If the Matlab command "diff" is used to compute the velocity, so I need to write six times for the six columns of matrix A_disp, like
V1 = diff(A_disp(:,1))./diff(b_time) ; V2 = diff(A_disp(:,2))./diff(b_time) ; V3 = diff(A_disp(:,3))./diff(b_time) ; V4 = diff(A_disp(:,4))./diff(b_time) ; V5 = diff(A_disp(:,5))./diff(b_time) ; V6 = diff(A_disp(:,6))./diff(b_time) ;
But this way seems not smart and makes the codes in matlab look bulky.
Are there any codes can deal with this issue in a simple and compact way?
Thanks so much!

回答(1 个)

Star Strider
Star Strider 2015-10-23
If your data are regularly-sampled (the sampling interval is constant), use the gradient function.
As I understand the description of your problem, the code for your derivative would be:
h = mean(diff(b_time));
[~,V] = gradient(A_disp, h);

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by