App designer - error using plot

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

 采纳的回答

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 个评论

Hello,
I am trying to plot by
Plot(app.UIAxes,f,Read5); in designer app but getting below error:
Undefined function 'Plot' for input arguments of type 'matlab.ui.control.UIAxes'.
My code into the designer app is as below:
classdef InrushCurrent_App1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
InsertFilenameEditFieldLabel matlab.ui.control.Label
FileName matlab.ui.control.EditField
PumpNumberEditFieldLabel matlab.ui.control.Label
PumpNumber matlab.ui.control.NumericEditField
ValueofmeasuredFrequencyEditFieldLabel matlab.ui.control.Label
Frequency matlab.ui.control.NumericEditField
PressForSamples matlab.ui.control.StateButton
TotalmeasuredsamplesEditFieldLabel matlab.ui.control.Label
Samples matlab.ui.control.NumericEditField
TimeofmeasurementsEditFieldLabel matlab.ui.control.Label
TotalTime matlab.ui.control.NumericEditField
FFTshouldstartfromSampleLabel matlab.ui.control.Label
FFTStart matlab.ui.control.NumericEditField
MultiplicationFactorEditFieldLabel matlab.ui.control.Label
MultiFactor matlab.ui.control.NumericEditField
EliminatepowerabovethisvalueLabel matlab.ui.control.Label
EliValue matlab.ui.control.NumericEditField
FFTPlotButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
Read10;
end
methods (Access = private)
% Value changed function: PressForSamples
function PressForSamplesValueChanged(app, event)
Read = xlsread(app.FileName.Value,'Inrush measurements'); % read the file
ColumnNumber = app.PumpNumber.Value; % assign the column to which we are interested for
Read2 = Read(:,ColumnNumber); %value of column assigned to Read2
app.Samples.Value = numel(Read2); % counting of number of measurements into Read2
Samples2 = app.Samples.Value;
fs = app.Frequency.Value; % Frequency value is assigned to fs
app.TotalTime.Value = (Samples2)/fs; % calculation to time of measurement
app.Read10.Value = Read2;
end
% Button pushed function: FFTPlotButton
function FFTPlotButtonPushed(app, event)
Rs = app.FFTStart.Value; % From where FFT graph will start
Read2 = app.Read10.Value;
Read3 = Read2(Rs:end,1); % assign values of measurements based on the Rs into Read3
Samples3 = numel(Read3); % counting of Read3
fs = app.Frequency.Value;
f = (0:Samples3-1)*(fs/Samples3); % making of the frequency vector
Read4 = fft (Read3); % FFT made from the Read3
Read4abs = abs(Read4); % absolute value has been taken from the Read4
Ps = app.MultiFactor.Value;
Eli = app.EliValue.Value;
Read4abs(Read4abs>Eli) = 0;
Read5 = Read4abs.^Ps;
Plot(app.UIAxes,f,Read5)
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 640 480];
app.UIFigure.Name = 'UI Figure';
% Create InsertFilenameEditFieldLabel
app.InsertFilenameEditFieldLabel = uilabel(app.UIFigure);
app.InsertFilenameEditFieldLabel.HorizontalAlignment = 'right';
app.InsertFilenameEditFieldLabel.Position = [15 434 91 22];
app.InsertFilenameEditFieldLabel.Text = 'Insert File name';
% Create FileName
app.FileName = uieditfield(app.UIFigure, 'text');
app.FileName.Position = [121 434 100 22];
% Create PumpNumberEditFieldLabel
app.PumpNumberEditFieldLabel = uilabel(app.UIFigure);
app.PumpNumberEditFieldLabel.HorizontalAlignment = 'right';
app.PumpNumberEditFieldLabel.Position = [23 389 83 22];
app.PumpNumberEditFieldLabel.Text = 'Pump Number';
% Create PumpNumber
app.PumpNumber = uieditfield(app.UIFigure, 'numeric');
app.PumpNumber.Limits = [0 Inf];
app.PumpNumber.ValueDisplayFormat = '%.0f';
app.PumpNumber.Position = [121 389 100 22];
% Create ValueofmeasuredFrequencyEditFieldLabel
app.ValueofmeasuredFrequencyEditFieldLabel = uilabel(app.UIFigure);
app.ValueofmeasuredFrequencyEditFieldLabel.HorizontalAlignment = 'right';
app.ValueofmeasuredFrequencyEditFieldLabel.Position = [1 344 105 28];
app.ValueofmeasuredFrequencyEditFieldLabel.Text = {'Value of measured'; 'Frequency'};
% Create Frequency
app.Frequency = uieditfield(app.UIFigure, 'numeric');
app.Frequency.Limits = [0 Inf];
app.Frequency.ValueDisplayFormat = '%.0f';
app.Frequency.Position = [121 350 100 22];
% Create PressForSamples
app.PressForSamples = uibutton(app.UIFigure, 'state');
app.PressForSamples.ValueChangedFcn = createCallbackFcn(app, @PressForSamplesValueChanged, true);
app.PressForSamples.Text = 'Press to know total samples';
app.PressForSamples.Position = [21 301 206 22];
% Create TotalmeasuredsamplesEditFieldLabel
app.TotalmeasuredsamplesEditFieldLabel = uilabel(app.UIFigure);
app.TotalmeasuredsamplesEditFieldLabel.HorizontalAlignment = 'right';
app.TotalmeasuredsamplesEditFieldLabel.Position = [3 256 136 22];
app.TotalmeasuredsamplesEditFieldLabel.Text = 'Total measured samples';
% Create Samples
app.Samples = uieditfield(app.UIFigure, 'numeric');
app.Samples.ValueDisplayFormat = '%.0f';
app.Samples.Editable = 'off';
app.Samples.Position = [157 256 72 22];
% Create TimeofmeasurementsEditFieldLabel
app.TimeofmeasurementsEditFieldLabel = uilabel(app.UIFigure);
app.TimeofmeasurementsEditFieldLabel.HorizontalAlignment = 'right';
app.TimeofmeasurementsEditFieldLabel.Position = [3 230 139 22];
app.TimeofmeasurementsEditFieldLabel.Text = 'Time of measurement (s)';
% Create TotalTime
app.TotalTime = uieditfield(app.UIFigure, 'numeric');
app.TotalTime.ValueDisplayFormat = '%.0f';
app.TotalTime.Editable = 'off';
app.TotalTime.Position = [157 230 72 22];
% Create FFTshouldstartfromSampleLabel
app.FFTshouldstartfromSampleLabel = uilabel(app.UIFigure);
app.FFTshouldstartfromSampleLabel.HorizontalAlignment = 'right';
app.FFTshouldstartfromSampleLabel.Position = [5 167 124 28];
app.FFTshouldstartfromSampleLabel.Text = {'FFT should start from '; 'Sample'};
% Create FFTStart
app.FFTStart = uieditfield(app.UIFigure, 'numeric');
app.FFTStart.ValueDisplayFormat = '%.0f';
app.FFTStart.Position = [143 173 86 22];
% Create MultiplicationFactorEditFieldLabel
app.MultiplicationFactorEditFieldLabel = uilabel(app.UIFigure);
app.MultiplicationFactorEditFieldLabel.HorizontalAlignment = 'right';
app.MultiplicationFactorEditFieldLabel.Position = [5 128 112 22];
app.MultiplicationFactorEditFieldLabel.Text = 'Multiplication Factor';
% Create MultiFactor
app.MultiFactor = uieditfield(app.UIFigure, 'numeric');
app.MultiFactor.Limits = [0 1000];
app.MultiFactor.ValueDisplayFormat = '%.0f';
app.MultiFactor.Position = [157 128 70 22];
% Create EliminatepowerabovethisvalueLabel
app.EliminatepowerabovethisvalueLabel = uilabel(app.UIFigure);
app.EliminatepowerabovethisvalueLabel.HorizontalAlignment = 'right';
app.EliminatepowerabovethisvalueLabel.Position = [1 86 130 28];
app.EliminatepowerabovethisvalueLabel.Text = {'Eliminate power above '; 'this value'};
% Create EliValue
app.EliValue = uieditfield(app.UIFigure, 'numeric');
app.EliValue.ValueDisplayFormat = '%.0f';
app.EliValue.Position = [157 92 70 22];
% Create FFTPlotButton
app.FFTPlotButton = uibutton(app.UIFigure, 'push');
app.FFTPlotButton.ButtonPushedFcn = createCallbackFcn(app, @FFTPlotButtonPushed, true);
app.FFTPlotButton.Position = [68 26 100 22];
app.FFTPlotButton.Text = 'FFT Plot';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [244 56 397 417];
end
end
methods (Access = public)
% Construct app
function app = InrushCurrent_App1
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
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
I have also tried with your answer (which -all plot) of but getting same error.
MATLAB is case sensitive. The function name should be in all lower case.
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?
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 个)

类别

帮助中心File 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