How can I make part of the interface disappear when changing selection in drop-down menu

I will start by apologising for the eventual poor quality of the code. I was working on a project, and part of it involves displaying different graphs, by selecting them from a drop-down menu. One of the graphs has editable Amplitude, frequency, etc, while the other should not. The problem I am facing is that if I first select the graph with adjustable parameters, whenever I choose the other one, the textboxes and editable boxes from the first graph are there. How can I make it so the Cardioid graph doesn't show the interface from the Sine?
^^this is how it should look like.
^^this it the other graph
^^this is what happens if I first select the Sine, and then the Cardioid
Here is my code:
function Extra
Fig=figure('Name','Extra',...
'Position' , [300 75 999 700],...
'Color', [ 0.8941 1.0000 0.7686],...
'NumberTitle','off');
uicontrol('Style','popupmenu',...
'Units','normalized',...
'String',{'1','2','<3'},...
'Position',[0.8 0.8 0.2 0.2],...
'Callback',['caz=','get(gco,''Value'');desen(caz);']);
uicontrol('Style','pushbutton',...
'Units','normalized',...
'Position',[0.4 0.05 0.2 0.05],...
'BackgroundColor',[ 1.0000 0.9686 0.8510],...
'String','Close',...
'Callback','close;');
end
function desen(caz)
if (caz == 3)
subplot('position',[0.1 0.2 0.8 0.7]);
t = linspace(-pi,pi, 350);
X = t .* sin( pi * .872*sin(t)./t);
Y = -abs(t) .* cos(pi * sin(t)./t);
plot(X,Y);
%fill(X, Y, 'r');
%axis square;
%set(gcf, 'Position', get(0,'Screensize'));
title('Cardioid', 'FontSize', 16);
elseif (caz == 2)
A = 10;
f = 50;
N = 4;
T = 1/f;
t = 0:T/100:N*T;
x=A*sin(2*pi*f*t);
uicontrol('Style','text',...
'Units','normalized',...
'Position',[0.9 0.83 0.08 .05],...
'Backgroundcolor',[0.5 0.5 0.9],...
'String','A');
uicontrol('Style','edit',...
'Units','normalized',...
'Position',[0.9 0.80 0.08 .05],...
'String','A',...
'Callback',['A=','str2num(get(gco,''String''));sine(A,f,N);']);
uicontrol('Style','text',...
'Units','normalized',...
'Position',[0.9 0.68 0.08 .05],...
'Backgroundcolor',[0.5 0.5 0.9],...
'String','f');
uicontrol('Style','edit',...
'Units','normalized',...
'Position',[0.9 0.64 0.08 .05],...
'String','f',...
'Callback',['f=','str2num(get(gco,''String''));sine(A,f,N);']);
uicontrol('Style','text',...
'Units','normalized',...
'Position',[0.9 0.53 0.08 .05],...
'Backgroundcolor',[0.5 0.5 0.9],...
'String','N');
uicontrol('Style','edit',...
'Units','normalized',...
'Position',[0.9 0.50 0.08 .05],...
'String','N',...
'Callback',['N=','str2num(get(gco,''String''));sine(A,f,N);']);
uicontrol('Style','pushbutton',...
'Units','normalized',...
'Position',[0.715 0.05 0.2 0.05],...
'String','Reset to Initial Values',...
'FontName','Arial',...
'Callback','sine(10,50,4);');
subplot('position',[0.1 0.2 0.75 0.7]);
plot(t,x);
grid on;
title('Sinus ');
xlabel('time [s]');
ylabel('Amplitude [V]');
else
end

Answers (1)

Before you call plot, call cla
cla('reset');

1 Comment

My problem was with the A, N, and f elements from the right side, not with the graph itself. cla(‘reset’); does not seem to fix it

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 14 Jan 2023

Commented:

on 14 Jan 2023

Community Treasure Hunt

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

Start Hunting!