📄 eyediasi.m
字号:
* timeRange(1) + timeRange(2);
last_time = x(3);
if ~handles(3)
x(3) = mod_time;
end;
if (mod_time < last_time)
if storeLength <= 0
storeLength = 1;
end
%hit the boundary of switching point.
pre_point = mod_time + timeRange(1);
aft_point = mod_time;
ind = [];
if sub_han(len_u+2) >= storeLength
ind = find(isnan(sub_han(len_u+3:length(sub_han))));
sub_han(len_u+3:ind(max(1, length(ind)-storeLength))) = [];
sub_han(len_u+2) = sum(isnan(sub_han(len_u+3:length(sub_han))));
end;
sub_han(len_u + 2) = sub_han(len_u + 2) + 1;
sub_han = [sub_han t NaN t];
set(handles(1),'UserData',sub_han);
for i = 1 : len_u
if sub_han(i)
tmp_x = get(sub_han(i), 'XData');
tmp_y = get(sub_han(i), 'YData');
if ~isempty(ind)
tmp_x(1:ind(max(1, length(ind)-storeLength))-len_u-2) = [];
tmp_y(1:ind(max(1, length(ind)-storeLength))-len_u-2) = [];
end;
set(sub_han(i), 'XData',[tmp_x, pre_point, NaN, aft_point],...
'YData',[tmp_y, u(i), NaN, u(i)]);
end;
end;
else
set(handles(1), 'UserData',[get(handles(1), 'UserData') t])
for i = 1 : len_u
if sub_han(i)
set(sub_han(i), 'XData', [get(sub_han(i), 'XData'), mod_time], ...
'YData', [get(sub_han(i), 'YData'), u(i)]);
end;
end;
end;
if triggered & sub_han(len_u) & (t > 0)
if storeLength <= 0
storeLength = 1;
end
tmp_x = get(sub_han(len_u + 1), 'XData');
tmp_y = get(sub_han(len_u + 1), 'YData');
if length(tmp_x) > 3*storeLength
tmp_x(1:3) = [];
tmp_y(1:3) = [];
end;
tmp_x = [tmp_x, mod_time, mod_time, NaN];
tmp_y = [tmp_y, get(handles(1), 'YLim'), NaN];
set(sub_han(len_u + 1), 'XData', tmp_x, 'YData', tmp_y);
end;
end;
if handles(2) & triggered & (t>0) & scatter_plot
if storeLength <= 0
storeLength = 1;
end
%scatter plot
sub_han = get(handles(2), 'UserData');
if changed_boundary
set(handles(2), 'Ylim', boundary);
if len_u == 2
set(handles(2), 'Xlim', boundary);
end;
end;
len_h_userdata = length(sub_han);
changed_line_type = 0;
if (length(scatterLine) ~= len_h_userdata - len_u)
changed_line_type = 1;
elseif max(abs(scatterLine) ~= sub_han(len_u+1:len_h_userdata))
changed_line_type = 1;
end;
if changed_line_type
lines = scatterLine;
for i = 1 : len_u
[col, lines] = strtok(lines, '/');
if length(col) <= 1
col = 'k-';
end;
if ~((i == 2) & (len_u == 2))
[linest, markst] = LineTypeSeparation(col(2:length(col)));
set(sub_han(i),...
'Color',col(1),...
'LineStyle', linest,...
'Marker', markst);
if col(2) == '.'
set(sub_han(i), 'MarkerSize', 10);
else
set(sub_han(i), 'MarkerSize', 6);
end;
end;
end;
set(handles(2), 'UserData',[sub_han(1:len_u), abs(scatterLine)]);
end;
if len_u == 2
tmp_x = get(sub_han(1), 'XData');
tmp_y = get(sub_han(1), 'YData');
if length(tmp_x) > 2*storeLength
tmp_x(1:2) = [];
tmp_y(1:2) = [];
end;
tmp_x = [tmp_x, u(1), NaN];
tmp_y = [tmp_y, u(2), NaN];
set(sub_han(1), 'XData', tmp_x, 'YData', tmp_y);
else
for i = 1 : len_u
tmp_x = get(sub_han(i), 'XData');
tmp_y = get(sub_han(i), 'YData');
if length(tmp_x) > 2*storeLength
tmp_x(1:2) = [];
tmp_y(1:2) = [];
end;
tmp_x = [tmp_x, 0, NaN];
tmp_y = [tmp_y, u(i), NaN];
set(sub_han(i), 'XData', tmp_x, 'YData', tmp_y);
end;
end;
end;
if handles(3) & two_d_plot
%2-d eye_plot
sub_han = get(handles(3), 'UserData');
if changed_boundary
set(handles(3), 'Xlim', boundary, 'Ylim', boundary);
end;
len_h_userdata = length(sub_han);
changed_line_type = 0;
if (length(twoDLine) ~= len_h_userdata - 2)
changed_line_type = 1;
elseif max(abs(twoDLine) ~= sub_han(3:len_h_userdata))
changed_line_type = 1;
end;
if changed_line_type
[col, lines] = strtok(twoDLine, '/');
if length(col) <= 1
col = 'k-';
end;
[linest, markst] = LineTypeSeparation(col(2:length(col)));
set(sub_han(1),...
'Color',col(1),...
'LineStyle',linest,...
'Marker', markst);
set(handles(3), 'UserData',[sub_han(1:2), abs(twoDLine)]);
end;
mod_time = rem((t - timeRange(2))/timeRange(1),1)...
* timeRange(1) + timeRange(2);
last_time = x(3);
x(3) = mod_time;
if mod_time < last_time
if storeLength <= 0
storeLength = 1;
end
tmp_x = get(sub_han(1),'XData');
tmp_y = get(sub_han(1),'YData');
if sub_han(2) >= storeLength
ind = find(isnan(tmp_x));
tmp_x(1:ind(1)) = [];
tmp_y(1:ind(1)) = [];
end;
tmp_x = [tmp_x u(1) NaN u(1)];
tmp_y = [tmp_y u(2) NaN u(2)];
set(handles(3),'UserData',[sub_han(1) sum(isnan(tmp_x)) abs(twoDLine)])
set(sub_han(1),'XData',tmp_x,'YData',tmp_y);
else
set(sub_han(1), 'XData', [get(sub_han(1), 'XData'), u(1)], ...
'YData', [get(sub_han(1), 'YData'), u(2)]);
end;
drawnow;
end;
sys = x;
% end mdlUpdate
%
%=============================================================================
% LocalFigureDeleteFcn
% This is the Graph figure window's DeleteFcn. The figure window is
% being deleted, update the Graph block's UserData to reflect the change.
%=============================================================================
%
function LocalFigureDeleteFcn
%
% Get the block associated with this figure and set it's figure to -1
%
SetEyediasiFigure(gcbh, get_param(gcbh,'userdata'));
close(gcbf);
% end LocalFigureDeleteFcn
%
%=============================================================================
% LocalBlockStartFcn
% Function that is called when the simulation starts. Initialize the
% Graph scope figure.
%=============================================================================
%
function LocalBlockStartFcn
%
% get the figure associated with this block, create a figure if it doesn't
% exist
%
figureHandle = GetEyediasiFigure(gcbh);
if ~ishandle(figureHandle),
figureHandle = CreateEyediasiFigure;
end
ud = get(figureHandle,'UserData');
set(figureHandle,'UserData',ud);
% end LocalBlockStartFcn
%
%=============================================================================
% LocalBlockStopFcn
% At the end of the simulation, set the line's X and Y data to contain
% the complete set of points that were acquire during the simulation.
% Recall that during the simulation, the lines are only small segments from
% the last time step to the current one.
%=============================================================================
%
function LocalBlockStopFcn
%
% Locate the figure window associated with this block. If it's not a valid
% handle (it may have been closed by the user), then return.
%
figureHandle=GetEyediasiFigure(gcbh);
if ishandle(figureHandle),
%
% Get UserData of the figure.
%
ud = get(figureHandle,'UserData');
% Currently do nothing in LocalBlockStopFcn
end
% end LocalBlockStopFcn
%
%=============================================================================
% LocalBlockNameChangeFcn
% Function that handles name changes on the Bit-Error Meter.
%=============================================================================
%
function LocalBlockNameChangeFcn
%
% the figure handle is stored in the block's UserData
%
figureHandle = GetEyediasiFigure(gcbh);
if ishandle(figureHandle),
set(figureHandle,'Name',get_param(gcbh,'Name'));
end
% end LocalBlockNameChangeFcn
%
%=============================================================================
% LocalBlockLoadCopyFcn
% Function that initializes the Bit-Error Meter's UserData when it is
% loaded from an mdl file and when it is copied.
%=============================================================================
%
function LocalBlockLoadCopyFcn
SetEyediasiFigure(gcbh,[]);
% end LocalBlockLoadCopyFcn
%
%=============================================================================
% LocalBlockDeleteFcn
% Function that handles the Bit-Error Meter's deletion from a block
% diagram.
%=============================================================================
%
function LocalBlockDeleteFcn
%
% the figure handle is stored in the block's UserData
%
figureHandle = GetEyediasiFigure(gcbh);
if ishandle(figureHandle),
delete(figureHandle);
SetEyediasiFigure(gcbh,[]);
end
% end LocalBlockDeleteFcn
%
%=============================================================================
% GetEyediasiFigure
% Retrieves the figure window associated with this S-function Bit-Error Meter
% from the block's parent subsystem's UserData.
%=============================================================================
%
function figureHandle=GetEyediasiFigure(block)
if strcmp(get_param(block,'BlockType'),'S-Function'),
block=get_param(block,'Parent');
end
ud = get_param(block,'UserData');
if ishandle(ud)
figureHandle = ud;
else
if isempty(ud)
ud.figureHandle = [];
set_param(block,'UserData', ud);
end;
figureHandle = ud.figureHandle;
end;
if isempty(figureHandle),
figureHandle = -1;
end
% end GetEyediasiFigure
%
%=============================================================================
% SetEyediasiFigure
% Stores the figure window associated with this S-function Bit-Error Meter
% in the block's parent subsystem's UserData.
%=============================================================================
%
function SetEyediasiFigure(block,figureHandle)
if strcmp(get_param(block,'BlockType'),'S-Function'),
block=get_param(block,'Parent');
end
ud = get_param(block,'UserData');
ud.figureHandle = figureHandle;
set_param(block,'UserData',ud);
% end SetEyediasiFigure
%
%=============================================================================
% CreateEyediasiFigure
% Creates the figure window associated with this S-function Bit-Error Meter.
%=============================================================================
%
function figureHandle=CreateEyediasiFigure
%
% create the figure and the axes
%
a = allchild(0);
b = findobj(a, 'Name', get_param(gcbh,'Name'));
if isempty(b)
figureHandle = figure(...
'Units', 'points',...
'Position', [10 10 360 350],...
'NumberTitle', 'off',...
'Name', get_param(gcbh,'Name'),...
'Visible', 'off', ...
'IntegerHandle','off',...
'DeleteFcn', 'eyediasi([],[],[],''DeleteFigure'')'...
);
else
figureHandle = b;
end;
set(0, 'CurrentFigure', figureHandle);
%
% store the block's handle in the figure's UserData
%
ud.Block = gcbh;
%ud.figureHandle = figureHandle;
%
% squirrel the figure handle away in the current block, and put the
% various handles into the figure's UserData
%
SetEyediasiFigure(gcbh,figureHandle);
set(figureHandle,'HandleVisibility','callback','UserData',ud);
% end CreateEyediasiFigure
%
%=============================================================================
% SetBlockCallbacks
% This sets the callbacks of the block if it is not a reference.
%=============================================================================
%
function SetBlockCallbacks(block)
%
% the actual source of the block is the parent subsystem
%
block=get_param(block,'Parent');
%
% if the block isn't linked, issue a warning, and then set the callbacks
% for the block so that it has the proper operation
%
if strcmp(get_param(block,'LinkStatus'),'none'),
% warnmsg=sprintf(['The Eye-Pattern diagram block ''%s'' should be replaced with a ' ...
% 'new version from the com_sour block library'],...
% block);
% warning(warnmsg);
callbacks={
'CopyFcn', 'eyediasi([],[],[],''CopyBlock'')' ;
'DeleteFcn', 'eyediasi([],[],[],''DeleteBlock'')' ;
'LoadFcn', 'eyediasi([],[],[],''LoadBlock'')' ;
'StartFcn', 'eyediasi([],[],[],''Start'')' ;
'StopFcn' 'eyediasi([],[],[],''Stop'')' ;
'NameChangeFcn', 'eyediasi([],[],[],''NameChange'')' ;
};
for i=1:length(callbacks)
if ~strcmp(get_param(block,callbacks{i,1}),callbacks{i,2})
set_param(block,callbacks{i,1},callbacks{i,2});
end
end
end
% end SetBlockCallbacks
%
%===============================================================
% Local Function
% This is used to separate the line type and mark type.
%===============================================================
%
function [linest, markst] = LineTypeSeparation(linetype)
% take out the marks
linest = linetype;
linidx = [findstr(linetype, '.'), ...
findstr(linetype, 'o'), ...
findstr(linetype, 'x'), ...
findstr(linetype, '+'), ...
findstr(linetype, '*'), ...
findstr(linetype, 's'), ...
findstr(linetype, 'd'), ...
findstr(linetype, 'v'), ...
findstr(linetype, '^'), ...
findstr(linetype, '<'), ...
findstr(linetype, '>'), ...
findstr(linetype, 'p'), ...
findstr(linetype, 'h')];
markst = 'none';
if ~isempty(linidx)
markst = linetype(linidx);
linest(linidx) = [];
end;
if isempty(linest)
linest = 'none';
end;
%%%%%%%%%%%%%%%%%%%%%%%%
% End of EYEDIASI.M %
%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -