?? udg.m
字號:
function [sys, x0, str, ts] = udg(t, x, u, varargin)
% UDG User-defined graphics.
% Plot data u in MATLAB figure.
% u is assumed to be Nx2; first column real-part, second column imag-part.
% Can also pass additional parameters to plot function
switch varargin{1}
case 3
sys = []; % mdlOutput - unused
case 2
sys = mdlUpdate(t, x, u, varargin{:});
case 0
[sys, x0, str, ts] = mdlInitializeSizes;
case 9
sys=mdlTerminate;
otherwise
feval(varargin{:});
end
% -----------------------------------------------------------
function [sys, x0, str, ts] = mdlInitializeSizes
blk = get_param(gcb, 'parent');
sizes = simsizes;
sizes.NumInputs = -1;
sizes.NumOutputs = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = []; % states
str = ''; % state ordering strings
ts = [-1 1]; % inherited sample time, fixed in minor steps
% initialize block data
bd = get_param(blk, 'userdata');
bd.firstcall = true;
bd.figTag = blk;
bd.graphicsName = get_param(blk, 'graphicsName');
bd.plotFcnHandle = str2func(bd.graphicsName);
set_param(blk, 'userdata', bd);
% ------------------------------------------------------------
function sys = mdlUpdate(t, x, u, flag, params)
% Faster implementation of: blk=gcb;
cs = get_param(0, 'CurrentSystem');
cb = get_param(cs, 'CurrentBlock');
sfcn = [cs '/' cb];
blk = get_param(sfcn, 'parent');
sys = [];
bd = get_param(blk, 'userdata');
% Form complex vector
u_complex = u(:, 1) + j*u(:, 2);
% Extra parameters
other_params = params;
other_params_exist = ~isempty(other_params);
% Need to check for figure every update (faster way?)
bd.fig = findobj('type', 'figure', 'tag', bd.figTag);
figExists = ~isempty(bd.fig);
if ~figExists && ~bd.firstcall
% Return if user closed figure during simulation.
return
end
if ~figExists
% figure is not open
bd.fig = figure;
set(bd.fig, 'tag', bd.figTag);
set(bd.fig, 'render', 'zbuffer');
set(bd.fig, 'numbertitle', 'off');
set(bd.fig, 'name', bd.figTag);
bd.axes = [];
bd.firstcall = true;
else
if bd.firstcall
figure(bd.fig);
end
end
% Call graphics function
if other_params_exist
feval(bd.plotFcnHandle, u_complex, bd.axes, bd.firstcall, other_params{:});
else
feval(bd.plotFcnHandle, u_complex, bd.axes, bd.firstcall)
end
if bd.firstcall
% get axes handles
[bd.axes, bd.multiple_axes] = get_axes_handles(bd.fig);
end
bd.firstcall = false;
set_param(blk, 'userdata', bd);
% ---------------------------------------------------------------
function sys = mdlTerminate
sys = [];
%--------------------------------------------------------------------------
function [haxes, multi] = get_axes_handles(fig);
% returns axes handles
% if there is only one axes, axes is a handle
% if more, axes is a structure of handles, with fieldnames corresponding to
% axes tags.
% to fix: return only children which are axes
% multi: true if more than one axes
c = findobj(fig, 'type', 'axes');
multi = (length(c)>1);
if ~multi
haxes = c;
else
t = get(c, 'tag');
h = num2cell(c);
x = [t(:).'; h(:).'];
haxes = struct(x{:});
end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -