how to take average with specific condition and write to excel file again ?

I had a excel file testM.xls data size(45*7)(as shown in Sheet1), first column shows the time and rest of the columns shows the values in 15 min interval for each hours. Now I want to take average of 4 values (for hourly basis data calculation) from corresponding hours and write there in excel file (as shown in Sheet2).

    % So Sheet2 data is calculated as:
    % for column 2nd of Sheet2: 
     B(2)=4.25        %average of values [B(2):B(5)] from Sheet1;
     B(3)=6        %average of values [B(6):B(9)] from Sheet1;
 % and so on till 
     B(12)=5      %average of values [B(42):B(45)] from Sheet1

Then how can I find using matlab for loop for all columns to find out the values hourly basis. Thanks

 Respuesta aceptada

clc
clear
A=xlsread('testM.xls');
AA=A(:,2:end);
AAA=squeeze(nanmean(reshape(AA,4,[],6),1))
xlswrite('testM.xls',[[0:10]' AAA],'sheet3','A1')

3 comentarios

If you want output to be exactly in the same format as in sheet2 (as your need), refer this
clc
clear
A=xlsread('testM.xls');
AA=A(:,2:end);
AAA=squeeze(nanmean(reshape(AA,4,[],6),1))
B=[[0:10]' AAA];
BB=arrayfun(@(x) num2str(x) , B,'uni',0);
table=[{'TIME','A','B','C','D','E','F'};BB]
xlswrite('testM.xls',table,'sheet3','A1')
Accept the answer if it helps you.
Thanks for your support and its very short code and working.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 1 de Oct. de 2018

Comentada:

el 2 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by