필터 지우기
필터 지우기

Create a plot with a drop down menu in an App

조회 수: 7 (최근 30일)
Hannes Robben
Hannes Robben 2020년 1월 23일
편집: Luna 2020년 1월 23일
Hello everybody,
i have the following problem and i dont know how to solve it:
I have created an app in Matlab and in this app i select a set of data, which i ll load into the workspace. Next i have 2 drop down menus. With these drop downs i want to select the x-axis and y axis of the workspace.
% Select the set off data and load the workspace variables in the drop down menu
% Button pushed function: ffnenButton
function ffnenButtonPushed(app, event)
[name,path] = uigetfile('*.dat', 'Bitte gewünschte dat-Datei auswählen');
if name==0 return, end
mdfimport(name);
vars = evalin('base', 'whos');
cell_array = cell(size(vars));
for i=1:length(vars)
cell_array{i} = vars(i).name;
end
app.dd_achse_x.Items = cell_array;
app.dd_achse_y.Items = cell_array;
end
% x Axis
% Value changed function: dd_achse_x
function dd_achse_xValueChanged(app, event)
xAchse = app.dd_achse_x.Value;
end
% y Axis
% Value changed function: dd_achse_y
function dd_achse_yValueChanged(app, event)
yAchse = app.dd_achse_y.Value;
end
% Create Graph
% Button pushed function: GrapherstellenButton
function GrapherstellenButtonPushed(app, event)
plot(xAchse,yAchse,'k-')
end
As seen above, i want to create a plot with the selected data. This plot should pop up in another figure with fig = uifigure ... etc.
But the problem is, that "xAchse" and "yAchse" are not defined in the function.
I hope that someone can help me. If you have any questions, just let me know.
Thanks

채택된 답변

Luna
Luna 2020년 1월 23일
편집: Luna 2020년 1월 23일
I think you don't even need to define callback functions for your dropdowns. They are already properties of your app object.
Basically you can do this:
function GrapherstellenButtonPushed(app, event)
plot(app.dd_achse_x.Value,app.dd_achse_y.Value,'k-')
end
There might be a problem. You should check app.dd_achse_y.Value is value of a dropdown item, it might be string or cell array of character vectors. So you might need to convert it to numerical value before you plot.
  댓글 수: 2
Hannes Robben
Hannes Robben 2020년 1월 23일
Yeah, you are right. There is a Problem with the Value of the dropdown item. It only saved the name of the vector.
Do you have any suggestion how i can fix it? There is a function str2num, but it doesnt work for this, at least i couldnt do it.
Luna
Luna 2020년 1월 23일
편집: Luna 2020년 1월 23일
Your values must be stored in an array or struct same fieldnames with your dropdown menu item names. Can you share your dropdown list or code related to that part? What do you want to plot actually according to these axis selections?

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

추가 답변 (1개)

Adam
Adam 2020년 1월 23일
app is your main application object. You can add properties to this yourself, which you can then access in any of its functions as e.g.
app.xAchse
You will need to add a manual properties block to the app (which should have private access normally, at least until you explicitly need external public access).

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by