How to find the difference between non-consecutive values

4 ビュー (過去 30 日間)
Joy
Joy 2024 年 4 月 1 日
編集済み: Voss 2024 年 4 月 1 日
How do I use diff() to find the difference between a certain number of indices? Furthermore, how do I turn the datetime into seconds to find the rate of X over time.
e.g., I have a datetime array t and another array X. I want to find the difference between every two elements of X and find the rate.
t1 = datetime(2013,11,1,8,0,0);
t2 = datetime(2013,11,5,8,0,0);
t = t1:t2
X = 1:5:25
for i = 1:2:length(X)
A = diff(X(i))/diff(seconds(t(i)))
end
However, I get an empty array in A.

採用された回答

Voss
Voss 2024 年 4 月 1 日
編集済み: Voss 2024 年 4 月 1 日
t1 = datetime(2013,11,1,8,0,0);
t2 = datetime(2013,11,5,8,0,0);
t = t1:t2
t = 1x5 datetime array
01-Nov-2013 08:00:00 02-Nov-2013 08:00:00 03-Nov-2013 08:00:00 04-Nov-2013 08:00:00 05-Nov-2013 08:00:00
X = 1:5:25
X = 1x5
1 6 11 16 21
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
A = diff(X(1:2:end))./seconds(diff(t(1:2:end)))
A = 1x2
1.0e-04 * 0.5787 0.5787
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by