フィルターのクリア

subtracting consecutive elements from arrays

2 ビュー (過去 30 日間)
C.G.
C.G. 2023 年 9 月 20 日
コメント済み: C.G. 2023 年 9 月 20 日
I have 2 arrays. To generate e, I want to subtract d from Q. After the first 10 times, I want to cycle back through Q for the next 10 times.
The result should be: e = [9 14 22 21 11 9 3 4 -1 3 9 14 23 21 13 9 3 -1 -1];
num = [50 51 53 51 50 55 56 57 53 54 55 56 58 55 54 57 58 59 60 61];
Q = [10 15.8 19.5 19.5 15.8 10 4.1 0.5 0.5 4.1];
d = diff(num);
e = round(Q - d);

採用された回答

dpb
dpb 2023 年 9 月 20 日
num = [50 51 53 51 50 55 56 57 53 54 55 56 58 55 54 57 58 59 60 61];
Q = [10 15.8 19.5 19.5 15.8 10 4.1 0.5 0.5 4.1];
d = [diff(num) nan];
e = round([Q Q] - d);
e=e(isfinite(e))
e = 1×19
9 14 22 21 11 9 3 5 -1 3 9 14 23 21 13 9 3 -1 -1
all(e==[9 14 22 21 11 9 3 4 -1 3 9 14 23 21 13 9 3 -1 -1])
ans = logical
0
I believe your posted answer is off by one in the 8th postion; should be 4, not 5...
  1 件のコメント
C.G.
C.G. 2023 年 9 月 20 日
thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by