Borrar filtros
Borrar filtros

Generate vector from cycle for

1 visualización (últimos 30 días)
matteo avanzi
matteo avanzi el 16 de Nov. de 2017
Editada: Andrei Bobrov el 16 de Nov. de 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

Respuestas (1)

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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by