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

1 visualización (últimos 30 días)
Stanley Cheng
Stanley Cheng el 23 de Oct. de 2015
Respondida: Star Strider el 23 de Oct. de 2015
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!

Respuestas (1)

Star Strider
Star Strider el 23 de Oct. de 2015
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);

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by