Compute wave energy converter power output using power matrix
4 views (last 30 days)
I have a matrix (88x72x8761) called 'SWH' representing a 20 year hindcast of hourly wave height (Hs) values at different geographic grid squares and another matrix (88x72x8761) called 'T02' representing a 20 year hindcast of hourly wave period values at the same geographic grid squares. I need to use the below wave energy converter power matrix to compute the power output at each grid square based on the wave height and period values at each geographic grid square for the 20 year time series. For example, starting at the top left of the below power matrix, and working from left to right, I need to find all of the occurences (pairs) of wave height=8 and wave period=2 and assign those pairs a value of 200, then I need to find all of the occurences (pairs) of wave height=8 and wave period=3 and assign those pairs a value of 100, and so on and so forth for each and every one of the 144 pairs in the matrix.
I've looked at histcounts2 as recommended by a colleague but I don't think it's the answer to this problem. Any ideas?
David Goodmanson on 6 Sep 2022
Edited: David Goodmanson on 6 Sep 2022
For the matrices SWH and T02, which I will call S and T, do they already meet the condition
S contains integers from 0 to 8; T contains integers from 2 to 17 ?
If they don't, the first thing would be to round down with e.g. S = floor(S), or round them up with ceil, or round them to the nearest integer with round, whatever is appropriate, same for T. So I'll assume that has been done. Your power matrix P has indices 0 to 8 for the rows and Matlab does not do zero-based indexing, so assume the rows are numbered 1 through 9 and make an adjustment later. There is no column 1 for P, but let's say P has 17 rows and fill the first row with NaNs as a safegurad and check. I don't want to type in all the P values so for test purposes let P have random values from 0 to 700 in hundreds.
H = 100*(randi(8,9,17)-1)
H(:,1) = nan; % first column
Now make S and T
S = randi(9,88,72,8761)-1; % 0 to 8
T = randi(16,88,72,8761)+1; % 2 to 17;
% Use S+1 so values 0 to 8 in S become rows 1 to 9 in P
U = H(S+1 + 9*(T-1)); % the result, same dimensions as S and T.
ans = logical 0 % ok