MATLAB: App designer – error using plot

app designer

Hi there. I'm having some trouble getting up and running with app designer. I've tried following several of the examples / demos in the documentation and also some videos on youtube. I get the same error every single time I try to run something: "Error using plot. Too many input arguments." Here's some code for a simple app that takes a numeric input to plot a curve:
classdef plotSin < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure % UI Figure
UIAxes matlab.ui.control.UIAxes
Label matlab.ui.control.Label % Type a v...
LabelNumericEditField matlab.ui.control.Label % a
NumericEditField matlab.ui.control.NumericEditField % [-Inf Inf]
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% NumericEditField value changed function
function NumericEditFieldValueChanged(app)
a = app.NumericEditField.Value;
x = 0:0.1:pi;
y = sin(a*x);
plot(app.UIAxes,x,y)
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 867 624];
app.UIFigure.Name = 'UI Figure';
setAutoResize(app, app.UIFigure, true)
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
xlabel(app.UIAxes, 'X');
ylabel(app.UIAxes, 'sin (ax)');
app.UIAxes.Position = [175 107 509 327];
% Create Label
app.Label = uilabel(app.UIFigure);
app.Label.FontSize = 18;
app.Label.Position = [362 561 149 23];
app.Label.Text = 'Type a value for a:';
% Create LabelNumericEditField
app.LabelNumericEditField = uilabel(app.UIFigure);
app.LabelNumericEditField.HorizontalAlignment = 'right';
app.LabelNumericEditField.FontSize = 18;
app.LabelNumericEditField.Position = [362 512 20 23];
app.LabelNumericEditField.Text = 'a';
% Create NumericEditField
app.NumericEditField = uieditfield(app.UIFigure, 'numeric');
app.NumericEditField.ValueChangedFcn = createCallbackFcn(app, @NumericEditFieldValueChanged);
app.NumericEditField.FontSize = 18;
app.NumericEditField.Position = [397 514 100 24];
end
end
methods (Access = public)
% Construct app
function app = plotSin()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

Best Answer

You have a plot.m function that is shadowing the built-in plot function. Type the following command to locate your plot.m and rename or remove it.
which -all plot