Plotting variables in app designer?

Hi, i created two dropdown objects in appdesigner and used this code for each object. It allows me to import variables from workspace.
function startupFcn(app)
vars = evalin('base', 'whos');
cell_array = cell(size(vars));
for i=1:length(vars)
cell_array{i} = vars(i).name;
end
app.XDropDown.Items = cell_array;
end
Now, i want to plot a graph with this variables.
How can i create a push button to plot?
I tried
function DrawButtonPushed(app,event)
xdropdown=app.XDropDown.Value;
ydropdown=app.YDropDown.Value;
plot(app.UIAxes,xdropdown,ydropdown)
end
But it gives error and says "Error using plot. Not enough arguments."
Thanks in advance!

답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 4월 26일

0 개 추천

You are getting this error because plot() require double as a second and third argument whereas you are providing its char array. Remember, although you have loaded names of all variables in the drop-down menu, it is simply name of the variable, not the numeric value. Change the plot command like this
plot(app.UIAxes, evalin('base', xdropdown), evalin('base', ydropdown));

댓글 수: 1

kbra htice
kbra htice 2018년 4월 26일
Thank you for your answer but it is not working for every variable. It only plots graph when the x and y variable are same.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2018년 4월 26일

댓글:

2018년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by