function varargout = SineFunc(varargin)
% SINEFUNC MATLAB code for SineFunc.fig
% SINEFUNC, by itself, creates a new SINEFUNC or raises the existing
% singleton*.
%
% H = SINEFUNC returns the handle to a new SINEFUNC or the handle to
% the existing singleton*.
%
% SINEFUNC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SINEFUNC.M with the given input arguments.
%
% SINEFUNC('Property','Value',...) creates a new SINEFUNC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SineFunc_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SineFunc_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 SineFunc
% Last Modified by GUIDE v2.5 16-Oct-2021 22:39:55
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SineFunc_OpeningFcn, ...
'gui_OutputFcn', @SineFunc_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 SineFunc is made visible.
function SineFunc_OpeningFcn(hObject, eventdata, 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 SineFunc (see VARARGIN)
% Choose default command line output for SineFunc
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SineFunc wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = SineFunc_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 on button press in Simulation.
function Simulation_Callback(hObject, eventdata, handles)
% hObject handle to Simulation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% A = '1';
% B = '2';
% load_system('SineDisplay'); %载入 SineDisplay.slx 模型(不需要这行代码)
% A = get(handles.Amplitude,'string'); %获取填入的幅值
Amplitude = findobj('tag','Amplitude'); % 解决问题:此类型的变量不支持使用点进行索引
A = get(Amplitude,'string');
% B = get(handles.Bias,'string'); %获取填入的偏移
Bias = findobj('tag','Bias'); % 解决问题:此类型的变量不支持使用点进行索引
B = get(Bias,'string');
set_param('SineDisplay/Sine Wave','Amplitude',A); %设置Simulink模块中的幅值参数
set_param('SineDisplay/Sine Wave','Bias',B); %设置Simulink模块中的偏移参数
options = simset('SrcWorkspace','current'); %设置仿真空间
sim('SineDisplay',[],options); %第一个参数为模型名,第二个参数为模型开始和结束时间组成的向量([]表示按照模型设置的运行时间,第三个参数为仿真空间)
% axes(handles.SineAxes); %将handles.SineAxes设置为当前坐标系
SineAxes = findobj('tag','SineAxes'); % 解决问题:此类型的变量不支持使用点进行索引
axes(SineAxes);
plot(ScopeData(:,1),ScopeData(:,2)); %利用Scope的图形数据绘制图形
grid on
function Amplitude_Callback(hObject, eventdata, handles)
% hObject handle to Amplitude (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Amplitude as text
% str2double(get(hObject,'String')) returns contents of Amplitude as a double
% --- Executes during object creation, after setting all properties.
function Amplitude_CreateFcn(hObject, eventdata, handles)
% hObject handle to Amplitude (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
function Bias_Callback(hObject, eventdata, handles)
% hObject handle to Bias (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Bias as text
% str2double(get(hObject,'String')) returns contents of Bias as a double
% --- Executes during object creation, after setting all properties.
function Bias_CreateFcn(hObject, eventdata, handles)
% hObject handle to Bias (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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