How to assign xlabel,ylabel from my selected popup menu list?

4 views (last 30 days)
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!!!

Answers (1)

Kevin Holly
Kevin Holly on 2 Oct 2021
Edited: Kevin Holly on 2 Oct 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 Comments
Vignesh Waran
Vignesh Waran on 2 Oct 2021
Edited: Vignesh Waran on 2 Oct 2021
Hi Kevin...I'm not using Appdesigner....Here is my code
X = get(handles.popupmenuX, 'value');
Y = get(handles.popupmenuY, 'value');
Z = get(handles.popupmenuZ, 'value');
filename = handles.filename;
[x,y,z] = readExcelColumns(filename, X, Y, Z)
axes(handles.axes1);
plot_style = get(handles.plotstyle,'value');
set(handles.statustext, 'Visible', 'on'); drawnow;
switch plot_style
case 2
scatter(handles.axes1,x,y,20,z,'filled');
grid on
colormap(jet);
colorbar;
case 3
scatter3(handles.axes1,x,y,z,[],z,'filled');
colormap(jet);
colorbar;
end
Kevin Holly
Kevin Holly on 2 Oct 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

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!