Reputation: 187
Hi I have a 3 dimensional matrix that I am trying to convert the rows to columns and then stack all the columns to generate a vector that will have the three dimensions.
therefore, row 1 becomes column 1, row 2 becomes column 2 etc. And then, column 2 goes under column 1, column 3 under column 1 and 2. I also need to keep the dimensions the same
PV_power_output(:,:,K) below is a 365 x 24 x 27 matrix, which should become a 8760x1 vector following the positioning sequence mentioned above
I am struggling with the coding of this
So far I have
PV_power_output(:,:,K) = real((Vmpp_(:,:,K).*Impp_(:,:,K))*inverter_efficiency)/1000;
permdims = 1 : ndims(PV_power_output);
out = reshape(permute(PV_power_output, permdims),8760,1,[]);
However, on checking the elements in different positions, the above is incorrect and so any help would be great!
Upvotes: 2
Views: 1369
Reputation: 3303
Perhaps your permute is wrong, because as it stands it's not doing anything:
permute(PV_power_output, 1:3) == PV_power_output
maybe you need:
permute(PV_power_output, [2 1 3])
I general I often find reshape difficult to follow (especially when you go back to the code three weeks later) so if performance is not critical then you could consider using a loop here instead for your 3d matrix.
You might think about a cell array instead of 3d matrix, and then your reshape is much more straight forward:
PV_power_output{K} = real((Vmpp_(:,:,K).*Impp_(:,:,K))*inverter_efficiency)/1000;
vector = reshape(PV_power_output{K},8760,1);
Update:
Perhaps try reshaping to 2D:
out = reshape(permute(PV_power_output, [2 1 3]), 8760,27);
And then you can access the Kth column vector as:
vector_K = out(:,K)
Upvotes: 1