📄 gui.m
字号:
function gui(varargin)%GUI Create and manage the graphic controls for CIMPULSE object% GUI(Signal, Pos) creates the controls in the rectangle of the current% figure described by Pos to let the user interactively change the CIMPULSE% object's parameters. Pos is in normalized units.%% GUI(Signal) assumes the position rectangle of [0 0 1 1]%% This function assumes a figure has already been created and that its% UserData property holds a CIMPULSE object.%% The function was written to be use within the SIGGENDLG function. %% Callbacks:% GUI('Replot') replots the Signal data with the current parameters and% stores the CIMPULSE data in the UserData property of the plot.%% GUI('Rescale Plot') rescales the x and y axis of the plot to fit the data.%% See also SIGGENDLG, CIMPULSE% Jordan Rosenthal, 05-Nov-1999
% Rev., 26-Oct-2000 Revised for name change to CIMPULSEswitch nargincase 1 action = 'Initialize'; Signal = varargin{1}; Pos = [0 0 1 1];case 2 Signal = varargin{1}; if ~isstr(varargin{2}) action = 'Initialize'; Pos = varargin{2}; else action = varargin{2}; endotherwise error('Illegal action.');endswitch actioncase 'Rescale Plot' Handles = getuprop(gcbf,'Handles'); rescaleplot(Signal,Handles.PlotAxis);case 'Replot' Handles = getuprop(gcbf,'Handles'); Values = get(Handles.Controls,'Value');
if Values{1} == 0
PlotHeight = 0;
else
PlotHeight = 1;
end Signal = cimpulse( ... 'Name',Signal.Name, ... 'Area',Values{1}, ... 'Delay',Values{2}, ...
'PlotHeight', PlotHeight ); set(gcbf,'UserData',Signal);
axes(Handles.PlotAxis); ezplot(Signal);
set(Handles.Title,'String',formulastring(Signal));
set(Handles.XLabel,'String',Signal.Name);
case 'Initialize' %%% Create Plot %%% Plot_Pos = [0.06*Pos(3)+Pos(1) 0.2*Pos(4)+Pos(2) 0.5*Pos(3) 0.7*Pos(4)]; hImpulse = ezplot(Signal); hTitle = title(formulastring(Signal), 'Color', 'b', 'FontUnits', 'normalized', ... 'FontSize',0.07); hXLabel = xlabel(Signal.Name, 'FontWeight', 'bold', 'FontUnits', 'normalized'); hAxes = gca; set(gca, 'Position', Plot_Pos, 'Box', 'on', 'NextPlot','ReplaceChildren', ...
'ButtonDownFcn','gui(get(gcbf,''UserData''),''Rescale Plot'')'); %%% Create rescale text message %%% Text_Pos = [0.06*Pos(3)+Pos(1) 0.05*Pos(4)+Pos(2) 0.5*Pos(3) 0.05*Pos(4)]; uicontrol('Units','normalized', ... 'BackgroundColor',get(0,'DefaultFigureColor'), ... 'ForegroundColor','r', ... 'FontUnits','normalized', ... 'Position',Text_Pos, ... 'String','Click inside plot area to rescale axis', ... 'Style','text'); %%% Create Controls %%% Controls_Pos = [0.6*Pos(3)+Pos(1) 0.2*Pos(4)+Pos(2) 0.38*Pos(3) 0.7*Pos(4)]; nParams = 2; Parameters = {'Area','Delay'}; Labels = {'Area:','Delay:'}; Values = num2str( [Signal.Area; Signal.Delay] ); Min = [-Inf; -Inf]; Max = [Inf; Inf]; Width = 0.1*ones(1,nParams); Height = 0.05*ones(1,nParams); Left = ( Controls_Pos(1) + Controls_Pos(3) - Width ) - 0.1; Bottom = Controls_Pos(2) + Controls_Pos(4)-Controls_Pos(4)/nParams*[0:nParams-1] - Height; NumEditPos = [Left; Bottom; Width; Height]; LabelWidth = 0.15*ones(1,nParams); LabelHeight = Height; LabelLeft = Left - 0.16; LabelBottom = Bottom - 0.005; LabelPos = [LabelLeft; LabelBottom; LabelWidth; LabelHeight]; DefFigColor = get(0,'DefaultFigureColor'); h = zeros(nParams,1); for i = 1:nParams uicontrol('Units','Normalized', ... 'Position',LabelPos(:,i), ... 'BackgroundColor',DefFigColor, ... 'FontUnits','normalized', ... 'FontWeight','Bold', ... 'HorizontalAlignment','right', ... 'String',Labels{i}, ... 'style','text'); h(i) = uinumedit('Units','normalized', ... 'BackgroundColor','w', ... 'CallBack','gui(get(gcbf,''UserData''),''Replot'')', ... 'Min', Min(i), ... 'Max', Max(i), ... 'Position',NumEditPos(:,i), ... 'String',Values(i,:)); end % Store handles for use in callbacks Handles.Controls = h; Handles.PlotAxis = hAxes; Handles.PlotLines = hImpulse;
Handles.Title = hTitle;
Handles.XLabel = hXLabel; setuprop(gcf, 'Handles', Handles); rescaleplot(Signal,Handles.PlotAxis);otherwise error('Illegal action.');end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% rescaleplot(Signal,hPlotAxis) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function rescaleplot(Signal,hPlotAxis)
XLim = Signal.Delay + [-10 10];
YLim = [-0.1 1.1];
set(hPlotAxis,'XLim',XLim,'YLim',YLim);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -