Plot function in app designer error "Not enough input arguments."

Hello every one,
I'm working on a little project where the main goal is to read a big excel file (xlsx) and extract information which interest me.
I need to make table and plot some value from this excel.
I import the excel file with the function readtable. However, when i want to plot with the data in the table, i have the following error :
Error using plot
Not enough input arguments.
Error in app2/ButtonPushed (line 53)
plot(app.UIAxes,x,y);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.
Thank you and i hope someone will help me !

 Akzeptierte Antwort

Arthur Roué
Arthur Roué am 29 Jul. 2020
x and y are structures, you need to select the correct field. For instance :
plot(app.UIAXes, x.freq_MHZ, i.iLdB)

13 Kommentare

Well actually, i made a mistake, th real code is the following one :
i use the function "table2array" and not "table2struct".
If i let the same code, i still have the error "Error using plot Not enough input arguments"
Which is weird, because i put the good amount of input arguments.
Indeed it's kinda weird.
Can you share the content of app.UIAxes, x and y ?
Hey,
here's the code
Maybe i can change the XTick for an {} and not a [] ?
Ok for UIAxes definition, can you add a breakpoint at your plot line and evaluate variable app.UIAxes, x and y ?
Yeah, i made a breakpoint on the plot and have this message :
I assume that app designer don't want to plot the x and y because it's an array.
Can you set the breakpoint before throwing the error ? I wanted to know the content of app.UIAxes, x and y before evaluation. Or better, can you share your app with the xlsxa data file ?
Yeah, i think it's better if i share the project. It's the first time i have this error and i'm a little lost.
And thank you for your time
Your problem is that x and y are cell-str because you use a table, plot function only take numerical arrays as input. If you load your data with readmatrix instead of readtable, it would be ok.
Now, if you want to keep a table object, you need to process a bit your x and y data before plotting
t = readtable('graphTest2_clean2.xlsx', 'Sheet', 1);
%ab = table2array(t);
app.UITable .Data = t; % associe le tableau excel à la var t
t.Properties.VariableNames{1} = 'freq_MHz';
t.Properties.VariableNames{2} = 'iLdB';
t.Properties.VariableNames{3} = 'pair12';
t.Properties.VariableNames{4} = 'pair34';
t.Properties.VariableNames{5} = 'NextdB';
t.Properties.VariableNames{6} = 'NextPair1236';
t.Properties.VariableNames{7} = 'RLdBLimit';
t.Properties.VariableNames{8} = 'RLpair12';
t.Properties.VariableNames{9} = 'RLPair36';
app.UITable.ColumnName = t.Properties.VariableNames ;
%x = ab(5:45,1);
% Get columns of table t
x = t.freq_MHz;
y = t.iLdB;
% There are empty values at the end of y. They are replaced by
% 'NaN' beforr numerical conversion
y(cellfun(@isempty, y)) = {'NaN'};
% Convert x and from cell-str to numerical array
x = cellfun(@str2num, x);
y = cellfun(@str2num, y);
% Plot
plot(app.UIAxes, x, y);
Thank you very much ! I understand now ! Have a nice day !
Y a pas de quoi, tu peux maintenant fermer la question et/ou accepter la réponse !
Bonne journée ;)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by