MATLAB: Means of a number of rows

meanrows

I have a table with 86400 rows and 4 columns. For each column I would like to calculate a mean for every 1800 rows. Finally, I expect to have a table with 48 rows and 4 columns.
Something like that is working, but it is too big…
u_mean=[mean(u(1:1800,1)) mean(u(1:1800,2)) mean(u(1:1800,3)) mean(u(1:1800,4));mean(u(1801:3600,1)) mean(u(1801:3600,2)) mean(u(1801:3600,3)) mean(u(1801:3600,4));mean(u(3601:5400,1)) mean(u(3601:5400,2)) mean(u(3601:5400,3)) mean(u(3601:5400,4));mean(u(5401:7200,1)) mean(u(5401:7200,2)) mean(u(5401:7200,3)) mean(u(5401:7200,4));mean(u(7201:9000,1)) mean(u(7201:9000,2)) mean(u(7201:9000,3)) mean(u(7201:9000,4));mean(u(9001:10800,1)) mean(u(9001:10800,2)) mean(u(9001:10800,3)) mean(u(9001:10800,4));mean(u(10801:12600,1)) mean(u(10801:12600,2)) mean(u(10801:12600,3)) mean(u(10801:12600,4));mean(u(12601:14400,1)) mean(u(12601:14400,2)) mean(u(12601:14400,3)) mean(u(12601:14400,4))];
Could you advice for something else?
Furthermore, if I have additionally a table with time (86400,3), first column for hour, second column for minutes and third column for seconds, there is a way to have means for rows in certain times?
Thanks.

Best Answer

data = rand(86400,4);
your_data = reshape(data,1800,[],4);
your_data = permute(your_data,[1 3 2]);
your_average = squeeze(mean(your_data,1))';
Please accept an answer if it helps you.