필터 지우기
필터 지우기

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 CenterFile 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