classdef Expression < handle
%Expression Evaluate a MATLAB expression
% Copyright 2008 The MathWorks, Inc.
% Author: Navan Ruthramoorthy
methods
function this = Expression()
end
function y = filter(this, data, Fs) %#ok<INUSD,INUSL>
y = [];
FigureHandle = figure( ...
'Visible','off', ...
'Menubar','none', ...
'Toolbar','none', ...
'Position', [360,500,550,150], ...
'IntegerHandle', 'off', ...
'Color', get(0, 'defaultuicontrolbackgroundcolor'), ...
'NumberTitle', 'off', ...
'Name', 'Audio Editor: Expression');
movegui(FigureHandle, 'center');
uicontrol('Parent', FigureHandle, 'Style', 'Text', ...
'String', ['Enter MATLAB expression to be evaluated in the base ' ...
'workspace. Audio data is available in the variable '...
'AudioData and sampling frequency is available in the ', ...
'variable Fs. The size of AudioData is ' ...
mat2str(size(data)) '.'], ...
'Units', 'Normalized', 'Position', [0 0.55 1 0.4], ...
'FontSize', 12);
uicontrol('Parent', FigureHandle, 'Style', 'Text', ...
'String', 'Expression:', ...
'Units', 'Normalized', 'Position', [0 0.3 0.2 0.2], ...
'FontSize', 12);
hExpr = uicontrol('Parent', FigureHandle, 'Style', 'edit', ...
'String', 'AudioData', ...
'Units', 'Normalized', 'Position', [0.2 0.3 0.7 0.2], ...
'FontSize', 12, 'BackgroundColor', 'white', ...
'HorizontalAlignment', 'left');
uicontrol('Parent', FigureHandle, 'Style', 'pushbutton', ...
'String', 'Evaluate', 'Units', 'Normalized', ...
'Position', [0.1 0 0.4 0.2], 'FontSize', 12, ...
'Callback', @(hobj, evd) applyCallback());
uicontrol('Parent', FigureHandle, 'Style', 'pushbutton', ...
'String', 'Cancel', 'Units', 'Normalized', ...
'Position', [0.5 0 0.4 0.2], 'FontSize', 12, ...
'Callback', @(hobj, evd) cancelCallback());
set(FigureHandle,'Visible','on', 'CloseRequestFcn', ...
@(hobj, evd) cancelCallback);
uiwait(FigureHandle);
function applyCallback()
assignin('base', 'AudioData', data);
assignin('base', 'Fs', Fs);
y = evalin('base', get(hExpr, 'String'));
szy2 = size(y, 2);
szd2 = size(data, 2);
if szy2 ~= szd2
% Expand if the number of channels do not match
y = repmat(y(:,1), 1, szd2);
end
delete(FigureHandle);
end
function cancelCallback()
y = data;
delete(FigureHandle);
end
end
end
methods (Static)
function name = getName()
name = 'MATLAB Expression';
end
end
properties (Access=private)
end
end