Guide (How to activate the checkbox?)

1 visualizzazione (ultimi 30 giorni)
wyeen chow
wyeen chow il 14 Dic 2020
Commentato: Jan il 16 Dic 2020
Hi all, I had try to plot the graph with GUIDE and I use check box to activate it. Focus on function time_Callback(hObject, eventdata, handles). Both time and frequency will be similar.
function varargout = demomo_DSBSC(varargin)
% DEMOMO_DSBSC MATLAB code for demomo_DSBSC.fig
% DEMOMO_DSBSC, by itself, creates a new DEMOMO_DSBSC or raises the existing
% singleton*.
%
% H = DEMOMO_DSBSC returns the handle to a new DEMOMO_DSBSC or the handle to
% the existing singleton*.
%
% DEMOMO_DSBSC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DEMOMO_DSBSC.M with the given input arguments.
%
% DEMOMO_DSBSC('Property','Value',...) creates a new DEMOMO_DSBSC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before demomo_DSBSC_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to demomo_DSBSC_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help demomo_DSBSC
% Last Modified by GUIDE v2.5 15-Dec-2020 02:33:07
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @demomo_DSBSC_OpeningFcn, ...
'gui_OutputFcn', @demomo_DSBSC_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before demomo_DSBSC is made visible.
function demomo_DSBSC_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to demomo_DSBSC (see VARARGIN)
% Choose default command line output for demomo_DSBSC
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes demomo_DSBSC wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = demomo_DSBSC_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function uipanel2_CreateFcn(hObject, eventdata, handles)
% hObject handle to uipanel2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in time.
function time_Callback(hObject, eventdata, handles)
% hObject handle to time (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of time
p=get(handles.popupmenu1);
t = -0.02 : 1.e-4:0;
t1 = -0.02 : 1.e-4:0;
t2= 0:1.e-4 :0.02;
Ta=0.01;
m1 = 1- abs((t1+Ta)/Ta);
m1= [zeros([1 200]), m1, zeros([1 400])];
m2 = 1- abs((t2-Ta)/Ta);
m2= [zeros([1 400]), m2, zeros([1 200])];
m=m1-m2; %message signal
fc= 400; %Frequency of carrier signal
c=cos(2*fc*pi*t); %carrier signal
dsb= 2*m.*c;% dsbsc signal
dem= dsb.*c;
a= fir1(25,100*1.e-4);
b=1;
switch(p)
case(1)
m;
case(2)
c;
case (3)
dsb;
case (4)
dem;
case (5)
rec=filter(a,b, dem);
end
y=modulate(m,c,dsb,dem,rec);
plot(t,y)
axis([-0.02,0,-2,2])
xlabel('time')
ylabel('amplitude')
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
My goal is when I choose the popmenu and activate one of the Signal, it will pop out one of the graph below. I had use switch and case to overcome this problem, but it do not works.
  4 Commenti
VBBV
VBBV il 16 Dic 2020
What is your question related to checkbox ? There are no createFcn function related to checkbox in your program
Jan
Jan il 16 Dic 2020
This piece of code is meaningless:
switch p
case 1
m;
case 2
c;
case 3
dsb;
case 4
dem;
c is a variable. Then c; displays its contents suppressing the output. Then this can be removed to clarify the code.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by