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 !

 採用された回答

Arthur Roué
Arthur Roué 2020 年 7 月 29 日

0 投票

x and y are structures, you need to select the correct field. For instance :
plot(app.UIAXes, x.freq_MHZ, i.iLdB)

13 件のコメント

Karol Szczech
Karol Szczech 2020 年 7 月 29 日
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"
Karol Szczech
Karol Szczech 2020 年 7 月 29 日
Which is weird, because i put the good amount of input arguments.
Arthur Roué
Arthur Roué 2020 年 7 月 29 日
Indeed it's kinda weird.
Can you share the content of app.UIAxes, x and y ?
Karol Szczech
Karol Szczech 2020 年 7 月 30 日
Hey,
here's the code
Maybe i can change the XTick for an {} and not a [] ?
Arthur Roué
Arthur Roué 2020 年 7 月 30 日
Ok for UIAxes definition, can you add a breakpoint at your plot line and evaluate variable app.UIAxes, x and y ?
Karol Szczech
Karol Szczech 2020 年 7 月 30 日
Yeah, i made a breakpoint on the plot and have this message :
Karol Szczech
Karol Szczech 2020 年 7 月 30 日
I assume that app designer don't want to plot the x and y because it's an array.
Arthur Roué
Arthur Roué 2020 年 7 月 30 日
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 ?
Karol Szczech
Karol Szczech 2020 年 7 月 30 日
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.
Karol Szczech
Karol Szczech 2020 年 7 月 30 日
And thank you for your time
Arthur Roué
Arthur Roué 2020 年 7 月 30 日
編集済み: Arthur Roué 2020 年 7 月 30 日
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);
Karol Szczech
Karol Szczech 2020 年 7 月 30 日
Thank you very much ! I understand now ! Have a nice day !
Arthur Roué
Arthur Roué 2020 年 7 月 30 日
Y a pas de quoi, tu peux maintenant fermer la question et/ou accepter la réponse !
Bonne journée ;)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by