MATLAB Examples

## tidal fitting toolbox

The tidal fitting toolbox simplifies the task of fitting tide models to time series. It is split into a tidalfit and a tidalval functions using the the familiar structure of polyfit and polyval.

```close all ```

## read in data.

First we load some hourly tide gauge observations from Richard's Bay, South Africa.

Datasource: RQDS http://ilikai.soest.hawaii.edu/uhslc/rqds.html

```data=load('h188a.mat'); plot(data.d(:,1),data.d(:,2),'k'); xlim([datenum('1 oct 2010') datenum('1 dec 2010')]) datetick('keeplimits') title(sprintf('%s, %s',data.header.name,data.header.region)) ``` ## Fit tidal model

Next we fit a tidal model to the entire data back to 1977. The resulting model is a structure which we later can pass to tidalval.

We use default options: OLS on detrended-data, automatic decision on which components to fit.

```model=tidalfit(data.d); ```
```lsqr converged at iteration 6 to a solution with relative residual 0.26. ```

## Make a tidal prediction

We then use the fitted model structure to predict the tide.

```t=(datenum('1 jan 2010'):1/24:datenum('1 dec 2010'))'; z=tidalval(model,t); %shift mean to match latest observations. z=z+nanmean(data.d(data.d(:,1)>datenum('1 oct 2010'),2)); hold on plot(t,z,'r') ``` 