Create a plot in UIAxes from a table using MATLAB App Designer

I'm trying to create a plot using the data from two colums in a table in the interface, as the following:
func = (app.EditField.Value);
a = (app.EditField_2.Value);
b = (app.EditField_3.Value);
n = (app.EditField_4.Value);
tol = (app.EditField_5.Value);
num = 0;
while (num < n)
fx = 2*tol;
if (abs(fx) > tol)
num = num + 1;
x = a;
fa = eval(func);
x = (a+b)/2;
fx = eval(func);
if (sign(fx) == sign(fa))
a = x;
vars = {num2str(num), num2str(a),num2str(b),num2str(x), num2str(fx)};
app.UITable.Data = [app.UITable.Data; vars];
else
b = x;
vars = {num2str(num), num2str(a),num2str(b),num2str(x), num2str(fx)};
app.UITable.Data = [app.UITable.Data; vars];
end
end
end
t = app.UITable.Data;
middle = t(:, 4);
fmiddle = t(:, 5);
plot(app.UIAxes, middle, fmiddle);
I can not see any errors in plot function, I mean all the arguements are set correctly, but I keep getting the error: 'Not enough arguments'! What is missing in the syntax of plot function? I have reviewed the documentation and everything was correctly added.

3 件のコメント

Ni2
Ni2 2019 年 10 月 16 日

Can you include screenshots of your app and codes

T.Mariah Khayat
T.Mariah Khayat 2019 年 10 月 16 日
The code is listed above in the question, it is only the solve button function.
BisectionApp.png
T.Mariah Khayat
T.Mariah Khayat 2019 年 10 月 16 日
May it is the way I'm getting the values from the columns?
Cause the plot function is working fine, for exmaple I can plot:
x = 0:0.02:2*pi;
y = sin(x);
plot(app.UIAxes, x, y);
and I see the plot on UIAxis.
But why not on the values of the table? do I have to change the x and y ticks? or what is the problem? What are the missing arguments?

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

回答 (1 件)

Himanshu Jain
Himanshu Jain 2021 年 8 月 24 日

0 投票

When you extract data from the UITable, it is returned in the table data structure. And when you extract any column from this table the also it is returned as a single column table.
Plot accepts data in the array format, that is why you are getting the error.
So you can replace
middle = t(:, 4);
fmiddle = t(:, 5);
with
middle = t{:, 4};
fmiddle = t{:, 5};
Now the 'middle' and 'fmiddle' will contain the data in the array format and it will plotted in the UIPlot.

カテゴリ

ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

質問済み:

2019 年 10 月 16 日

回答済み:

2021 年 8 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by