Help with reshaping a matrix variable

1 Ansicht (letzte 30 Tage)
venkat siddhartha rama
venkat siddhartha rama am 21 Okt. 2019
Beantwortet: Payas Bahade am 25 Okt. 2019
Hello friends,
I have drawn to give better understanding of problem and also detailely explained below. If any one of you know possible solution that I missed, please feel free to let me know and if I lissed anything please feel fre to ask me.
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

Akzeptierte Antwort

Payas Bahade
Payas Bahade am 25 Okt. 2019
Hi Venkat,
For the problem with solution 2, following code can be used to extract individual column variables from ‘Interpreted_power’:
Interpreted_power_1st_column=Interpreted_power(:,1);
Interpreted_power_2st_column=Interpreted_power(:,2);
Interpreted_power_3st_column=Interpreted_power(:,3);
Interpreted_power_4st_column=Interpreted_power(:,4);
Interpreted_power_5st_column=Interpreted_power(:,5);
For more details, refer following documentation link on how to index a particular row/column:https://www.mathworks.com/help/matlab/math/array-indexing.html?searchHighlight=indexing&s_tid=doc_srchtitle
However, a more efficient approach would be writing a ‘for’ loop to traverse through all the columns of the variable ‘Interpreted_power’ and calculate ‘hourly_wind_energy’using the code below,
Interpreted_power = ones(105120,5); % put your interpreted power matrix here
hourly_wind_energy = ones(8760,5); % Dummy variable pre-allocation
for i=1:5
temp_interp = Interpreted_power(:,i);
temp_hourly =((sum(reshape(temp_interp*5,12,8760)))/60);
hourly_wind_energy(:,i) = temp_hourly';
end
HTH!

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by