Azzera filtri
Azzera filtri

Generate vector from cycle for

3 visualizzazioni (ultimi 30 giorni)
matteo avanzi
matteo avanzi il 16 Nov 2017
Modificato: Andrei Bobrov il 16 Nov 2017
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

Risposte (1)

Andrei Bobrov
Andrei Bobrov il 16 Nov 2017
Modificato: Andrei Bobrov il 16 Nov 2017
Variants without use loops
day1 = mean(reshape(Gen,86400,[]));
or
day1 = accumarray(ceil((1:numel(Gen))'/86400),Gen,[],@mean);

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by