Using a drop down menu or pushbuttons to display graphs

1 回表示 (過去 30 日間)
Alexander Link
Alexander Link 2019 年 3 月 10 日
コメント済み: Walter Roberson 2019 年 3 月 10 日
I am trying to create an interactive interface that has a drop down menu with two options "2D Plot" and "3D Plot" and when one of these options is selected it launches the respected graph. I am finding the drop down menu to be kinda complicated for me so if having two push buttons is easier then that will also work. Here is what I have with my code so far but I keep getting a message that says "Error while evaluation UIControl Callback". Please let me know if you can help! Thank you!
global Figure2D Figure3D
[num,txt,raw] = xlsread('Surface_Data.xlsx', 'PDA-PTFE_PFQNM_SA003ASCII3', 'A2:SR513');
[ny,nx] = size(num);
L = 20; %micrometer
B = 20; %micrometer
x = linspace(0,L,nx);
y = linspace(0,B,ny);
[X,Y] = meshgrid(x,y);
Figure2D = figure;
pcolor(X,Y,num);
Figure3D = figure;
surf(X,Y,num);
plotStyle2D = uicontrol(Figure2D,'Style','popupmenu');
plotStyle2D = uicontrol(Figure3D,'Style','popupmenu');
menuItems = [" Select Plot " "2D Plot" "3D Plot"];
dropDownPosition = [20 80 100 40];
plotStyle2D.String = menuItems;
plotStyle2D.Position = dropDownPosition;
plotStyle3D.String = menuItems;
plotStyle3D.Position = dropDownPosition;
plotStyle2D.Callback = @PlotType;
H
function PlotType(src,event)
val = src.Value;
str = src.String;
if(str{val} == '2D Plot')
figure(Figure2D);
elseif(str{val} == '3D Plot')
figure(Figure3D);
end
end
  4 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 10 日
What are the other errors you are getting?
Walter Roberson
Walter Roberson 2019 年 3 月 10 日
You should also be setting the Callback for plotStyle3d

サインインしてコメントする。

回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 3 月 10 日
does this work for you?
function PlotType(src,event)
val = src.Value;
str = src.String;
if strcmp(src.String,'2D Plot')
figure(Figure2D);
elseif strcmp(src.String,'3D Plot')
figure(Figure3D);
end
end
  1 件のコメント
Alexander Link
Alexander Link 2019 年 3 月 10 日
No nothing is really working

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by