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

조회 수: 8 (최근 30일)
Vignesh Waran
Vignesh Waran 2021년 10월 2일
댓글: Kevin Holly 2021년 10월 2일
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개)

Kevin Holly
Kevin Holly 2021년 10월 2일
편집: Kevin Holly 2021년 10월 2일
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
Vignesh Waran
Vignesh Waran 2021년 10월 2일
편집: Vignesh Waran 2021년 10월 2일
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 2021년 10월 2일
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

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

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by