Hi all,
I have a vector with 8352 rows and I want to find the max value from each consecutive 288 rows, e.g 1:288, 289:577 etc. So I should end up with 29 max values
I am struggling with making a for loop with this
The vector size will change of course depending on the dataset I am using so need to account for this when reusing the loop
Thanks

 採用された回答

Jan
Jan 2017 年 2 月 24 日
編集済み: Jan 2017 年 2 月 24 日

1 投票

x = rand(8352, 1);
x = reshape(x, 288, []);
y = max(x, [], 1);
And if the length is not a multiple of the window size:
Win = 288;
Len = size(x, 1);
LenP = Len - mod(Len, Win);
x = reshape(x(1:LenP), 288, []);
y = max(x, [], 1);
yRest = max(x(LenP:Len), [], 1);

5 件のコメント

Jamie Mcwilliam
Jamie Mcwilliam 2017 年 2 月 24 日
Deleted my previous question as was not correct - I have a correpsonding time vector (8352x1) [5 min increments] I now want to measure the time difference between max values times and values from another vector (peak_chorus) [29x1] and have this as a new vector with the time difference in hours
Thanks Jan -
Jamie Mcwilliam
Jamie Mcwilliam 2017 年 2 月 24 日
Hi Jan,
Thanks but I still have the task of working out
1. the corresponding Max times rows from the time vector 2. The time difference between the max time rows and vector_peak
The code below solves the second part - I just need part 1 deltasec = etime(datevec(max_time_vector),datevec(peak_time_vector)); deltah = deltasec/60/60;
Jamie Mcwilliam
Jamie Mcwilliam 2017 年 2 月 24 日
simple question - how do I get the index of the max value of x so that I can filter the other time vector rows with that index. That will solve all my problems
cheers
Adam
Adam 2017 年 2 月 24 日
編集済み: Adam 2017 年 2 月 24 日
doc max
would tell you that the 2nd output argument gives you this:
[y,idx] = max(...);
Jamie Mcwilliam
Jamie Mcwilliam 2017 年 2 月 24 日
Hi adam, yep I did use this but because the vector is reshaped the corresponding index does not match my time vector (8352x1)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by