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 !
采纳的回答
x and y are structures, you need to select the correct field. For instance :
plot(app.UIAXes, x.freq_MHZ, i.iLdB)
13 个评论
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 ;)
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Tables 的更多信息
产品
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
