A Matlab notebook primer

This notebook is not tested in our CIs and require some extra configuration from the users. You'll need to install octave and the t_tide toolbox.

A common misconception is that Jupyter notebooks are for Python only. We already showed how to use the R language, and now we are going to create a Matlab/Octave toolboxes notebook.

The IOOS conda environment installs oct2py, the dependency needed to run Matlab/Octave notebooks. However, unlike R that can be installed with conda, we cannot install Matlab or Octave with it. This notebook relies on system installation of octave but it is possible to run the same on Matlab with very little modification.

Here are some basic Matlab-like array creation and dot multiplication.

x = [1, 2, 3]
y = [1; 2; 3]

z = x*y
x =

   1   2   3

y =

   1
   2
   3

z =  14

And a simple plot.

x = linspace(0, 2*pi, 100);
y = sin(x);

plot(x, y)
../../../_images/2017-03-30-octave_notebook_example_6_0.png

To demonstrate the Matlab/Octave notebook we will use a well known toolbox for tidal analysis t_tide. First we need to add it to the path.

addpath(genpath('t_tide_v1.3beta'))

If you are running this on octave you need to load the signal package. This step is not necessary on Matlab.

pkg load signal;

t_demo is a built-in script that contains a short example of capabilities of tidal analysis toolbox.

t_demo
+ echo ('on')
+ ## Load the example.
+ load ('t_example')
warning: load: file found in load path
+ ## Define inference parameters.
+ infername = ['P1'; 'K2'];
+ inferfrom = ['K1'; 'S2'];
+ infamp = [.33093; .27215];
+ infphase = [-7.07; -22.40];
+ ## The call (see t_demo code for details).

+ ## hourly data

+ ## start time is datestr(tuk_time(1))

+ ## Latitude of obs

+ ## Add a shallow-water constituent 

+ ## coloured boostrap CI
+ [tidestruc, pout] = t_tide (tuk_elev, 'interval', 1, 'start', tuk_time (1), 'latitude', 69 + 27 / 60, 'inference', infername, inferfrom, infamp, infphase, 'shallow', 'M10', 'error', 'linear', 'synthesis', 1);
warning: /home/filipe/IOOS/notebooks_demos/notebooks/t_tide_v1.3beta/t_tide.m: possible Matlab-style short-circuit operator at line 443, column 18
warning: /home/filipe/IOOS/notebooks_demos/notebooks/t_tide_v1.3beta/t_tide.m: possible Matlab-style short-circuit operator at line 637, column 19
warning: load: file found in load path
   number of standard constituents used: 35
   Forced fit to M10
   Inference of P1   using K1  
   Inference of K2   using S2  
   Points used: 1510 of 1584
   percent of var residual after lsqfit/var original: 74.18 %
warning: /home/filipe/IOOS/notebooks_demos/notebooks/t_tide_v1.3beta/t_vuf.m: possible Matlab-style short-circuit operator at line 68, column 22
warning: load: file found in load path
   Greenwich phase computed with nodal corrections applied to amplitude 
 and phase relative to center time
   Do inference corrections
   Using linearized error estimates
   Generating prediction with nodal corrections, SNR is 1.000000
warning: /home/filipe/IOOS/notebooks_demos/notebooks/t_tide_v1.3beta/t_predic.m: possible Matlab-style short-circuit operator at line 66, column 34
warning: /home/filipe/IOOS/notebooks_demos/notebooks/t_tide_v1.3beta/t_predic.m: possible Matlab-style short-circuit operator at line 173, column 18
warning: isstr is obsolete and will be removed from a future version of Octave, please use ischar instead
warning: load: file found in load path
warning: load: file found in load path
   percent of var residual after synthesis/var original: 78.42 %
-----------------------------------
date: 29-Mar-2017
nobs = 1584,  ngood = 1510,  record length (days) = 66.00
start time: 06-Jul-1975 01:00:00
rayleigh criterion = 1.0
Greenwich phase computed with nodal corrections applied to amplitude \n and phase relative to center time

x0= 1.98, x trend= 0

var(x)= 0.82196   var(xp)= 0.17966   var(xres)= 0.64461
percent var predicted/var original= 21.9 %

     tidal amplitude and phase with 95% CI estimates

tide   freq       amp     amp_err    pha    pha_err     snr
 MM   0.0015122    0.2121    0.521   263.34   140.72     0.17
 MSF  0.0028219    0.1561    0.521   133.80   191.29     0.09
 ALP1 0.0343966    0.0152    0.035   334.95   143.54     0.19
 2Q1  0.0357064    0.0246    0.035    82.69    89.79     0.48
 Q1   0.0372185    0.0158    0.035    65.74   140.51      0.2
*O1   0.0387307    0.0764    0.035    74.23    29.21      4.7
 NO1  0.0402686    0.0290    0.035   238.14    53.29     0.67
*P1   0.0415526    0.0465    0.035    71.88    43.41      1.7
*K1   0.0417807    0.1405    0.035    64.81    15.24       16
 J1   0.0432929    0.0253    0.035     7.32    86.65     0.51
*OO1  0.0448308    0.0531    0.035   235.75    43.75      2.3
 UPS1 0.0463430    0.0298    0.035    91.73    87.12     0.71
 EPS2 0.0761773    0.0211    0.025   184.59    66.90      0.7
*MU2  0.0776895    0.0419    0.025    83.23    33.79      2.8
*N2   0.0789992    0.0838    0.025    44.52    16.86       11
*M2   0.0805114    0.4904    0.025    77.70     2.89  3.8e+02
 L2   0.0820236    0.0213    0.025    35.22    82.98     0.71
*S2   0.0833333    0.2197    0.025   126.72     6.58       76
*K2   0.0835615    0.0598    0.025   149.12    28.01      5.6
 ETA2 0.0850736    0.0071    0.025   246.05   244.76     0.08
*MO3  0.1192421    0.0148    0.010   234.97    40.62      2.3
*M3   0.1207671    0.0123    0.010   261.57    44.22      1.6
 MK3  0.1222921    0.0049    0.010   331.60   117.53     0.25
 SK3  0.1251141    0.0023    0.010   237.69   252.59    0.057
*MN4  0.1595106    0.0092    0.009   256.47    52.74      1.1
*M4   0.1610228    0.0126    0.009   291.78    38.58        2
 SN4  0.1623326    0.0083    0.009   270.85    59.58     0.89
 MS4  0.1638447    0.0010    0.009   339.35   479.33    0.014
 S4   0.1666667    0.0047    0.009   299.56   108.15     0.28
 2MK5 0.2028035    0.0013    0.005   310.10   214.09    0.073
 2SK5 0.2084474    0.0045    0.005   104.00    62.55     0.94
 2MN6 0.2400221    0.0035    0.007   271.24   101.52     0.28
 M6   0.2415342    0.0017    0.007   158.88   207.26    0.067
 2MS6 0.2443561    0.0056    0.007   306.10    65.10     0.71
 2SM6 0.2471781    0.0023    0.007   298.92   165.13     0.12
*3MK7 0.2833149    0.0086    0.004   212.25    29.47      3.7
 M8   0.3220456    0.0030    0.003    42.43    56.78     0.86
 M10  0.4025570    0.0009    0.003   198.23   195.47     0.07
+ ## Use SNR=1 for synthesis. 
+ echo ('off')
warning: get: allowing linewi to match line property linewidth
error: get: ambiguous text property name vertical; possible matches:

verticalalignment      verticalalignmentmode

error: called from:
error:   /usr/share/octave/3.8.2/m/plot/appearance/text.m at line 152, column 17
error:   /home/filipe/IOOS/notebooks_demos/notebooks/t_tide_v1.3beta/t_demo.m at line 57, column 1
../../../_images/2017-03-30-octave_notebook_example_12_1.png