How to assign xlabel,ylabel from my selected popup menu list?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone,
I have created a basic GUI which plots scatter plot in 2D and 3D
Based on 3 popup menus i.e.X,Y,Z graphs gets plotted.
I want to assign xlabel, y label and z label based upon selected variable from popupmenu
x,y,z labels should get automatically updated upon changing variable from popup menu.
I have tried using get,set functions but I could not do it.
Any help on this topic!!!
1 Kommentar
Antworten (1)
Kevin Holly
am 2 Okt. 2021
Bearbeitet: Kevin Holly
am 2 Okt. 2021
If App Designer:
value = app.DropDown.Value;
value2 = app.DropDown2.Value;
value2 = app.DropDown2.Value;
if value == 'Option 2' & value2 == 'Option 3' & value3 == 'Option 3'
xlabel(app.UIAxes,'X Label')
ylabel(app.UIAxes,'Y Label')
zlabel(app.UIAxes,'Z Label')
else
xlabel(app.UIAxes,'X Label2')
ylabel(app.UIAxes,'Y Label2')
zlabel(app.UIAxes,'Z Label2')
end
If uicontrol:
c = uicontrol(f,'Style','popupmenu','callback',@DropDownCallback); % dropdown box 1
c2 = uicontrol(f,'Style','popupmenu','callback',@DropDownCallback); % dropdown box 2
c3 = uicontrol(f,'Style','popupmenu','callback',@DropDownCallback); % dropdown box 3
value = c.Value;
value2 = c2.Value;
value2 = c3.Value;
function DropDownCallback(~,~)
if value == 'Option 2' & value2 == 'Option 3' & value3 == 'Option 3'
xlabel('X Label')
ylabel('Y Label')
zlabel('Z Label')
else
xlabel('X Label2')
ylabel('Y Label2')
zlabel('Z Label2')
end
end
2 Kommentare
Kevin Holly
am 2 Okt. 2021
I'm not sure how you created your popupmenus. I'm going to assume with uicontrol.
handles.popupmenuX = uicontrol(gcf,'Style','popupmenu','Units','normalized','Position',[.5 .5 .2 .2],'String',{'Option 1','Option 2','Option 3'},'Callback',@DropDownCallback);
handles.popupmenuY = uicontrol(gcf,'Style','popupmenu','Units','normalized','Position',[.3 .3 .2 .2],'String',{'Option 1','Option 2','Option 3'},'Callback',@DropDownCallback);
handles.popupmenuZ = uicontrol(gcf,'Style','popupmenu','Units','normalized','Position',[.7 .7 .2 .2],'String',{'Option 1','Option 2','Option 3'},'Callback',@DropDownCallback);
function DropDownCallback(~,~)
X = get(handles.popupmenuX, 'value');
Y = get(handles.popupmenuY, 'value');
Z = get(handles.popupmenuZ, 'value');
plot_style = get(handles.plotstyle,'value');
set(handles.statustext, 'Visible', 'on'); drawnow;
filename = handles.filename;
[x,y,z] = readExcelColumns(filename, X, Y, Z);
if X == 1 && Y == 2 && Z == 3
plot_style = 2;
else
plot_style = 3;
end
switch plot_style
case 2
scatter(handles.axes1,x,y,20,z,'filled');
grid on
colormap(jet);
colorbar;
xlabel('X Label')
ylabel('Y Label')
zlabel('Z Label')
case 3
scatter3(handles.axes1,x,y,z,[],z,'filled');
colormap(jet);
colorbar;
xlabel('X Label2')
ylabel('Y Label2')
zlabel('Z Label2')
end
end
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!