Function: counting occurrences using 1 vector to count in another

Hi!
I have 2 vectors.
Beta = 0.4, 0.5, 0.6 1.2, 1.9, 2, 5.3, 6.7
wins = 0.4, 1.2;
1.3, 6.7.
Beta represents hit points in seconds - something occurred at 0.4 seconds, 0.5 seconds etc. Wins represents timeframes identified as important - I need to look at the timeframe between 0.4 and 1.2. I'm creating a function where there are likely to be more beta hits and more time frames. I need to examine how many hit points took place in a specific timeframe and then average it. The numbers are presented as seen and does not have time stamps.
So;
Hits = sum((beta>=wins(1,1) & beta<=wins(1,2))) = 4
timescale=wins(1,2)-wins(1,1) = 0.8 seconds
hits/timescale (4/0.8) = 5 hits average.
What amendment to the code do I need to make it run through all the time frames identified by wins and provide all the averages?

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 6 月 9 日

0 投票

Try this
Beta = [0.4, 0.5, 0.6 1.2, 1.9, 2, 5.3, 6.7];
wins = [0.4, 1.2;
1.3, 6.7];
avg_vals = zeros(size(wins,1), 1);
for i=1:size(wins, 1)
avg_vals(i) = sum(discretize(Beta, wins(i,:)), 'omitnan')/diff(wins(i,:));
end

2 件のコメント

Nick Storr
Nick Storr 2020 年 6 月 9 日
編集済み: Nick Storr 2020 年 6 月 9 日
I'm afraid this didn't work. I'll keep looking
Ameer Hamza
Ameer Hamza 2020 年 6 月 9 日
Can you tell what the expected output for the given input vectors is?

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

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

質問済み:

2020 年 6 月 9 日

コメント済み:

2020 年 6 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by