フィルターのクリア

Generate vector from cycle for

1 回表示 (過去 30 日間)
matteo avanzi
matteo avanzi 2017 年 11 月 16 日
編集済み: Andrei Bobrov 2017 年 11 月 16 日
I have some problem with for cycle. First problem:
I have this vector Gen of 2678400 values, and its shape is shown in figure. I want to create a for cycle that calculate the mean value from the vector Gen every 86400 values. like from 1*86400 to 2*86400 ---> mean value 1 from 2*864400 to 3*86400 ---> mean value 2 etc etc until the end. And i want that the cycle generate a vector M that contain all the 30 mean values.
I tried with this
for i=1:30
day=Gen(i*86400:(i+1)*86400);
M=mean(day);
but the code get me to the ws just the last vector day from 30*86400 to 31*86400 and just the mean value M that corresponds to that interval.
Second problem: is it possible to do the mean value only between the values that are different from zero for each of the thirty curves?
thanks a lot

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 16 日
編集済み: Andrei Bobrov 2017 年 11 月 16 日
Variants without use loops
day1 = mean(reshape(Gen,86400,[]));
or
day1 = accumarray(ceil((1:numel(Gen))'/86400),Gen,[],@mean);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by