App designer - error using plot

14 次查看(过去 30 天)
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

采纳的回答

Steven Lord
Steven Lord 2016-8-30
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
  4 个评论
Sparsh Bansal
Sparsh Bansal 2020-6-1
Even when I delete the files in the MATLAB directory, 'which -all plot' call still shows all the plot.m in the folder. Is there some way to reload MATLAB? I have tried restarting MATLAB multiple times but they still persist.
Also these plot.m files were installed by MATLAB itself, I have not installed anything on my own, so how are they causing this error?
Steven Lord
Steven Lord 2020-6-1
Do not store your own personal files in any of the directories under matlabroot.
Do not delete any files in any of the directories under matlabroot unless specifically told to do so by Technical Support.
If you receive an error, post the full and exact text of the error you receive (all the text displayed in red, and if you see any text displayed in orange show that too) and show or describe exactly what you can do to reproduce the error.

请先登录,再进行评论。

更多回答(1 个)

Eebs Ebola
Eebs Ebola 2016-8-30
BEAUTIFUL!!!! Thank you so much.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by