Take the sum of an array until a limit is reached determined by a vector of the same length

3 ビュー (過去 30 日間)
I have a scatter graph made from two arrays of equal length,
How may I take the sum of the intensities per an arbituary track length of 10mm? I know it might have something to do with cumsum, any help would be much apprieciated, cheers.
For any example maybe consider these two smaller arrays:
TL = [1,1,2,2,1,3,3,3,4,5,5];
I = [1,1,1,1,3,3,1,6,6,6,5];

採用された回答

Turlough Hughes
Turlough Hughes 2020 年 2 月 24 日
For a single result you could write the following to get the sum for an arbitrary track length of 10 mm, and you have the option of replacing 10 with any other track length you wish to find the cumulative sum for.
result = sum(I(TL<10))
You could also use cumsum as well if you sort the arrays according to TL beforehand:
[TL,index] = sort(TL);
I = I(index);
Ics = cumsum(I);
  4 件のコメント
HenT2020
HenT2020 2020 年 2 月 25 日
Thank you very much! This solution works perfectly and allows for an easy change in track length. Thanks again for taking the time to help solve this problem
Turlough Hughes
Turlough Hughes 2020 年 2 月 25 日
Happy to help. I modified to the relational operators slightly, see above edit.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by