フィルターのクリア

Difference of two 2-dimensional matrices

16 ビュー (過去 30 日間)
MeEngr
MeEngr 2015 年 1 月 18 日
コメント済み: Star Strider 2015 年 1 月 19 日
Dear all,
I have the x and y positions of a certain object at 1 second intervals in time. The x positions are stored inside a 1xn matrix, where n is the number of seconds for which the data was obtained. The y positions are also stored inside a 1xn matrix, where n is again the number of seconds for which the object was observed. Now I need to obtain the velocity of the object. I could obtain the x and y velocities separately and store them inside two new matrices by using the diff() function on both x and y position matrices, but I need the velocity of the object as a whole. Can anybody please advise what to do? Thanks.

採用された回答

Star Strider
Star Strider 2015 年 1 月 18 日
編集済み: Star Strider 2015 年 1 月 18 日
There are actually at least a couple ways to go about this. In either situation, I would use both the hypot and gradient functions.
The first option is to use gradient after the distance calculations:
x = sort(rand(20,1)); % Create Data: ‘X’ Position
y = sort(rand(20,1)); % Create Data: ‘Y’ Position
t = sort(rand(20,1)); % Create Data: ‘Time’
xyd = hypot(x,y); % Pythagorean Theorem Distance Calculation
v = gradient(xyd, t); % Velocity
The second option is to use gradient first to calculate the individual x and y velocities, then use hypot to calculate the net velocity:
vx = gradient(x, t); % ‘X’ Velocity
vy = gradient(y, t); % ‘Y’ Velocity
vn = hypot(vx, vy); % ‘Net’ Velocity
The code is similar in both situations.
I would experiment with both to determine the most accurate calculation. The choice is yours.
  2 件のコメント
MeEngr
MeEngr 2015 年 1 月 18 日
Thank you so much!
Star Strider
Star Strider 2015 年 1 月 19 日
My pleasure!

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2015 年 1 月 18 日
v=diff(y)./diff(t);
  2 件のコメント
MeEngr
MeEngr 2015 年 1 月 18 日
Hi dpb, I'm sorry but can you please elaborate? What is diff(y)? Is y the name of the y-position matrix? And t the name of the time array? If yes to both questions, then how do I get the total velocity of the object? As in, I need both x and y velocities as a single number.
dpb
dpb 2015 年 1 月 18 日
Sorry, I misread as distance, time vectors, not x,y. See Star to convert to position first...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by