필터 지우기
필터 지우기

two for Nested Loops

조회 수: 1 (최근 30일)
ahmad Saad
ahmad Saad 2017년 12월 14일
댓글: ahmad Saad 2017년 12월 15일
How i can sum the third column to get the average over each 24 values of the second coloumn?
  댓글 수: 2
KL
KL 2017년 12월 14일
편집: KL 2017년 12월 14일
sounds more like making daily sum from hourly data. Use a timetable!
ahmad Saad
ahmad Saad 2017년 12월 14일
KL
Yes, it is the daily sum from hourly data. but How the time table can be used?

댓글을 달려면 로그인하십시오.

답변 (6개)

Jos (10584)
Jos (10584) 2017년 12월 14일
편집: Jos (10584) 2017년 12월 14일
Your question is a little unclear. Do you want to sum all values of the third row when the second row equals 0, equals 1, etc, so you end up with 24 summed values? That is easy:
A = xlsread('average24');
S = accumarray(A(:,2)+1, A(:,3), [24,1], @mean)
% S(k) is the average of all values of A(:,3) when A(:,2) equals (k-1)
  댓글 수: 1
Jos (10584)
Jos (10584) 2017년 12월 14일
you want the average, answer corrected! :)

댓글을 달려면 로그인하십시오.


Jan
Jan 2017년 12월 14일
편집: Jan 2017년 12월 14일
Maybe
A = xlsread('average24');
% Average over blocks of 24 values:
S1 = mean(reshape(A(:, 3), 24, []), 1);
% Or average over all values belonging to 0, 1, 2, ...:
S2 = mean(reshape(A(:, 3), 24, []), 2);

KL
KL 2017년 12월 14일
편집: KL 2017년 12월 15일
An example with timetable,
EDITED
%import data
data = readtable('actual data.txt');
%create a proper datetime column
data.Timestamp = datetime(cell2mat(data{:,[1 2]}),'InputFormat','yyyy.MM.ddHH:mm');
%keep only datetime and measurements
data = data(:, [end 3]);
%create timetable
TT = table2timetable(data(:,2),'rowtimes',data.Timestamp);
%calculate daily mean
TT_mean = retime(TT,'daily','mean');

ahmad Saad
ahmad Saad 2017년 12월 14일
I'm very grateful for all. i'll check the answers and feek back
the answers are really helpfull
thanks again

ahmad Saad
ahmad Saad 2017년 12월 15일
This the actual data
from 1/10/2017 to 30/11/2017 the output should have 61 values
  댓글 수: 4
KL
KL 2017년 12월 15일
편집: KL 2017년 12월 15일
The answer I gave you works on your text file. I tested it before posting it here!
This is the output
TT_mean =
61×1 timetable
Time Var3
__________ ______
2017-10-01 9383.2
2017-10-02 9388.9
2017-10-03 9420.8
2017-10-04 9449.3
2017-10-05 9463
2017-10-06 9456.5
2017-10-07 9406.2
2017-10-08 9364.3
2017-10-09 9386.4
2017-10-10 9440.3
...
ahmad Saad
ahmad Saad 2017년 12월 15일
KL
OK
i'll try again and feedback; thanks for your kind attention

댓글을 달려면 로그인하십시오.


ahmad Saad
ahmad Saad 2017년 12월 15일
Birdman
deep thanks, it works fine, thanks : Birdman

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by