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일
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
Can you tell what the expected output for the given input vectors is?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Resizing 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