Generate vector from cycle for
2 views (last 30 days)
Show older comments
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
Answers (1)
Andrei Bobrov
on 16 Nov 2017
Edited: Andrei Bobrov
on 16 Nov 2017
Variants without use loops
day1 = mean(reshape(Gen,86400,[]));
or
day1 = accumarray(ceil((1:numel(Gen))'/86400),Gen,[],@mean);
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!