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

1 回表示 (過去 30 日間)
Stanley Cheng
Stanley Cheng 2015 年 10 月 23 日
回答済み: Star Strider 2015 年 10 月 23 日
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 Center および File ExchangeMATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by