Reshaping 2d array

8 views (last 30 days)
venkat siddhartha rama
venkat siddhartha rama on 20 Oct 2019
Edited: Andrei Bobrov on 22 Oct 2019
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
  4 Comments
David Hill
David Hill on 22 Oct 2019
Since you have an algorithm for (105120x1), just pass all columns into the function.
secondCol=powerMatrix(:,2);
thirdCol=powerMatrix(:,3);
Sebastian Bomberg
Sebastian Bomberg on 22 Oct 2019
I don't know which release you're on but starting from 2016b, if you had your data stored in a timetable you could simply call retime:
Thourly = retime(T,'hourly','mean')

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 22 Oct 2019
Edited: Andrei Bobrov on 22 Oct 2019
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'});

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!