How to minus two arrays with condition

2 ビュー (過去 30 日間)
Tipnirin Vajanarat
Tipnirin Vajanarat 2019 年 11 月 6 日
コメント済み: Tipnirin Vajanarat 2019 年 11 月 10 日
My title may not be clear but lets say if I have two sets of time data, A and B.
These two arrays dont have the same size and I want the value of B-A. From my data A will never be bigger than B in the same row.
For example: A starts at 4th second and B starts at 1st second
A(time) B(time)
1
2.5
4 5
8 11
14 17
how to skip first two of B data in order to get B-A?
appreciate all the answers

採用された回答

Ruger28
Ruger28 2019 年 11 月 6 日
編集済み: Ruger28 2019 年 11 月 6 日
A = [4 8 14]
B = [1 2.5 5 11 17]
C = B(3:end) - A % take only the variables from 3 to end of vector
A more dynamic approach, assuming B always starts at 1 and A can be at different times
%% Assumng B always starts at 1
A(3:5) = [4 8 14]; % generate A with empty values in first 3 positions
B = [1 2.5 5 11 17];
[rowVal,colVal] = find(A); % find non-zero elements in A
newA = A(colVal); % only uses valid values of A
newB = B(colVal); % only uses same values that A has
C = newB - newA;
  1 件のコメント
Tipnirin Vajanarat
Tipnirin Vajanarat 2019 年 11 月 10 日
Thank you so much. appreciate

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by