0

Finding maximum values of wave heights and wave lengths

dwcL01 though dwcL10 is arrays of <3001x2 double> with output from a numerical wave model.

Part of my script:

%% Plotting results from SWASH
% Examination of phase velocity on deep water with different number of layers
% Wave height 3 meters, wave peroid 8 sec on a depth of 30 meters
clear all; close all; clc;
T=8;
L0=1.56*T^2;

%% Loading results tabels.
load dwcL01.tbl; load dwcL02.tbl; load dwcL03.tbl; load dwcL04.tbl;
load dwcL05.tbl; load dwcL06.tbl; load dwcL07.tbl; load dwcL08.tbl;
load dwcL09.tbl; load dwcL10.tbl;
M(:,:,1) = dwcL01; M(:,:,2) = dwcL02; M(:,:,3) = dwcL03; M(:,:,4) = dwcL04;
M(:,:,5) = dwcL05; M(:,:,6) = dwcL06; M(:,:,7) = dwcL07; M(:,:,8) = dwcL08;
M(:,:,9) = dwcL09; M(:,:,10) = dwcL10;

%% Finding position of wave crest using diff and sign.
for ii=1:10
    Tp(:,1,ii) = diff(sign(diff([M(1,2,ii);M(:,2,ii)]))) < 0;
    Wc(:,:,ii) = M(Tp,1,ii);
    L(:,ii) = diff(Wc(:,1,ii))
end

The loop

for ii=1:10
    Tp(:,1,ii) = diff(sign(diff([M(1,2,ii);M(:,2,ii)]))) < 0;
    Wc(:,:,ii) = M(Tp,1,ii);
    L(:,ii) = diff(Wc(:,1,ii))
end

Works fine for ii = 1 Getting the following error for ii = 2

Index exceeds matrix dimensions.

Error in mkPlot (line 19)
   Wc(:,:,i) = M(Tp,:,i);

Don't have the same number of wave crests for the different set ups, naturally M(Tp,1,ii) will have different dimensions. How do I work around this issue? Can it be done in a for loop? please feel free to email me or other wise ask for further information.

Malthe Eisum
  • 189
  • 11
  • 1
    You can try turning `Wc` into a cell: `Wc{i} = M(Tp,:,i)`. Then you don't have to worry about different sizes of `M(Tp,:,i)` at each instance of your `for`-loop. – Schorsch Oct 17 '13 at 16:38
  • 1
    As a note on the side: [Using `i` and `j` as variables in Matlab](http://stackoverflow.com/questions/14790740/using-i-and-j-as-variables-in-matlab) – Schorsch Oct 17 '13 at 16:39
  • In addition: What size is `Tp` at each iteration? Maybe the assignment `M(Tp,:,i)` creates issues. – Schorsch Oct 17 '13 at 17:24

1 Answers1

0

The problem is that Tp is a three dimensional array. I need to call the Tp(:,:,ii) corresponding to the present scenario. Together with this and defining Wc as a cell I solve my issue.

for ii = 1:10
    Tp(:,1,ii) = diff(sign(diff([M(1,2,ii);M(:,2,ii)]))) < 0;
    Wc{:,:,ii} = M(Tp(:,:,ii),1,ii);
    L{:,ii} = diff(cell2mat(Wc(ii)));
end
Malthe Eisum
  • 189
  • 11