Asked by venkat siddhartha rama
on 20 Oct 2019 at 13:04

greetings friends,

Problem Definition:

I had a variable named Interpreted_power_1st_column = 105120 X 1 ;

- This is the power availablitiy data at a location collected at every 5 mins interval for whole year.( 8760*12=105120) (there are 12 5 mins intervals in 1 hour ,and 8760 hours in 365 days)
- I want the data to be avaerged to 1 hour interval, so I used reshape function in matlab( code below) to sum the 12 consequtive data points multiply by 5 and then divide the whole summation by 60....this is actually good way to get average data for 1 hour interval.

hourly_wind_energy1=zeros(8750,1);

hourly_wind_energy1=((sum(reshape(Interpreted_power*5,12,8760)))/60); %Hourly Wind energy generated from intepretation of power curve KW-hr

hourly_wind_energy1=hourly_wind_energy1';%%Hourly Wind energy generated from intepretation of power curve KW-hr

Now I have to do the same but Interpreted_power = 105120 X 5 (5 columns)

I have be trying various ways like for loops but couldnot achieve my final result.

Possible solution 1 : any experts who are well aware of reshape function help me with a possible way to do the process I have done in problem definityin for an variable with several columns (for now 105120 X 5, 5 columns)

Possible solution 2:

- to create 5 different variables (Interpreted_power_1st_column, Interpreted_power_2nd_column, Interpreted_power_3rd_column, Interpreted_power_4th_column, Interpreted_power_5th_column)
- Interpreted_power_1st_column has 1st column of Interpreted_power = 105120 X 5
- Interpreted_power_2nd_column has 2nd column of Interpreted_power = 105120 X 5
- Interpreted_power_3rd_column has 3rd column of Interpreted_power = 105120 X 5
- Interpreted_power_4th_column has 4th column of Interpreted_power = 105120 X 5
- Interpreted_power_5th_column has 5th column of Interpreted_power = 105120 X 5

Now follow the same procedure used in Problem definition ( Use reshape function 5 times for 5 of these variables, then combine all the results into single variable with 8760 X 5 )

Problem with solution 2 : I am having trouble creating individual column variables,

Interpreted_power_1st_column=Interpreted_power(1:end);

Interpreted_power_1st_column=Interpreted_power_1st_column'; %% this is giving 1st column elements

Interpreted_power_2st_column=Interpreted_power(2:end);

Interpreted_power_2st_column=Interpreted_power_2st_column'; %% but all below are not exactly the required column elements

Interpreted_power_3st_column=Interpreted_power(3:end);

Interpreted_power_3st_column=Interpreted_power_3st_column';

Interpreted_power_4st_column=Interpreted_power(4:end);

Interpreted_power_4st_column=Interpreted_power_4st_column';

Interpreted_power_5st_column=Interpreted_power(5:end);

Interpreted_power_5st_column=Interpreted_power_5st_column';

Thanks in advance

Answer by Andrei Bobrov
on 22 Oct 2019 at 13:08

Edited by Andrei Bobrov
on 22 Oct 2019 at 13:44

Accepted Answer

As in comment by Sebastian Bomberg's (for MATLAB >= R2016b):

% Let A - your data of energy (150120 x 5 double)

TT = array2timetable(A,'RowTimes',(datetime(2018,1,1,0,0,0):minutes(5):datetime(2018,12,31,23,55,0))');

TT_hourly_mean = retime(TT,'hourly','mean');

if MATLAB <= R2016a:

[y,m,d,h,~,~] = datevec((datetime(2018,1,1,0,0,0):minutes(5):datetime(2018,12,31,23,55,0))');

T = [table(y,m,d,h),array2table(A)];

T_hourly_mean = varfun(@mean,T,'GroupingVariable',{'y','m','d','h'});

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## David Hill (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486397-reshaping-2d-array#comment_758348

## venkat siddhartha rama (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486397-reshaping-2d-array#comment_758356

## David Hill (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486397-reshaping-2d-array#comment_758843

## Sebastian Bomberg (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/486397-reshaping-2d-array#comment_759017

Sign in to comment.