Up to now, all the activity of the tutorial has been carried out on the MATLAB command terminal. It is, of course, much more convenient to collect the commands together in to a MATLAB script. In this sense, LTPDA scripting is just the same as normal MATLAB scripting; just using LTPDA commands.

There are, however, one or two caveats to that, especially when it comes to preserving the history. Most notably, indexing and concatenating objects is not captured by the history if you use standard MATLAB notation.

For example, suppose you have two AOs which you want to make a Transfer function between them. The following script shows three different ways to do this, but only two will properly track the history.

%% Make two test AOs

a1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 100));
a2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 100));

%% Make TFE with multiple outputs

[t11, t21, t12, t22] = tfe(a1,a2);
Axx = t12 ./ t21; 

%% Make TFE then index with ()

txx = tfe(a1,a2);
Axx = txx(1,2) ./ txx(2,1); % <-- BREAKS THE HISTORY

%% Use index method

txx = tfe(a1,a2);
Axx = txx.index(1,2) ./ txx.index(2,1); 

You can explore the commands used to rebuild the object by using the type method. Or you can plot the history as we did earlier. For example, try this command for each of the three cases above:

  type(Axx)

You should see that in the second case, the history doesn't include the indexing of the output of the tfe method when doing the division. As a result, the output of the division will be a 4 element vector of AOs, not the single AO we were expecting.