Using a Class to create MATLAB functions. An dvanced user can create a MATLAB custom analysis function by subclassing
instrument.integration.AlgorithmDefinition. The waterfall.m class shows an example of this type of custom analysis function. This
is more complex than using a function but allows more control of behavior than the basic function capability. By using a subclass,
you can implement custom tear-down behaviors, such as closing plots automatically when an analysis function is no longer being
called.
Your class should be a subclass of instrument.integration.AlgorithmDefinition:
classdef myClass < instrument.integration.AlgorithmDefinition
There are four methods your class may need to implement: a constructor, a destructor, a process, and a stopProcessingHook.
The default destructor and stopProcessingHook from the superclass may be sufficient for your class. However, at minimum you
need to implement a constructor and the process function:
classdef myClass < instrument.integration.AlgorithmDefinition
methods
function obj = myClass(sampleRate,pointsPerRecord)
obj@instrument.integration.AlgorithmDefinition(sampleRate,pointsPerRecord);
end
function [result] = process(obj,varargin)
result = varargin{1};
end
end
end
The constructor is called the first time the analysis function is used in a specific math expression on the instrument. Here
anything that requires setup before processing data, such as plots, should be configured. The parent constructor can be called
from your custom construct if necessary (the constructor for AlgorithmDefinition sets up some basic settings information about
the instrument).
The process function is the main workhorse of the class. This function computs results and returns data to the instrument. Like
the custom analysis functions created using the basic function interface, the length of the results returned by your process
function should match the length of the input.
The stopProcessingHook function is called when the analysis function is no longer in use by the instrument. This may happen
when you edit or clear a math function, or in other situations when the instrument math system expects that the state should be
reset. For example, if your analysis function is displaying a plot, this would be the time to close the plot.
Finally, the destructor is called when the analysis function is no longer in use. Typically you call the stopProcessingHook function
from here to aid in cleanup.
Oscilloscope reference
DPO70000SX, MSO/DPO70000DX, MSO/DPO70000C, DPO7000C, and MSO/DPO5000B Series 715