function [sys, x0, str, ts] = sfunxyauto(t,x,u,flag,ax,varargin)
%SFUNXYAUTO S-function that acts as an X-Y scope using MATLAB plotting functions.
% This M-file works exactly the same as SFUNXY, except that it autoscales
% the axes on each time step.
%
% This M-file is designed to be used in a Simulink S-function block.
% It draws a line from the previous input point, which is stored using
% discrete states, and the current point. It then stores the current
% point for use in the next invocation.
%
% See also SFUNXY, SFUNXYS, LORENZS.
% This user-contributed S-function is not supported by The MathWorks.
% Greg Aloe
% Version 1.0
% 4-24-2002
switch flag
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0
[sys,x0,str,ts] = mdlInitializeSizes(ax,varargin{:});
SetBlockCallbacks(gcbh);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2
sys = mdlUpdate(t,x,u,flag,ax,varargin{:});
%%%%%%%%%
% Start %
%%%%%%%%%
case 'Start'
LocalBlockStartFcn
%%%%%%%%
% Stop %
%%%%%%%%
case 'Stop'
LocalBlockStopFcn
%%%%%%%%%%%%%%
% NameChange %
%%%%%%%%%%%%%%
case 'NameChange'
LocalBlockNameChangeFcn
%%%%%%%%%%%%%%%%%%%%%%%%
% CopyBlock, LoadBlock %
%%%%%%%%%%%%%%%%%%%%%%%%
case { 'CopyBlock', 'LoadBlock' }
LocalBlockLoadCopyFcn
%%%%%%%%%%%%%%%
% DeleteBlock %
%%%%%%%%%%%%%%%
case 'DeleteBlock'
LocalBlockDeleteFcn
%%%%%%%%%%%%%%%%
% DeleteFigure %
%%%%%%%%%%%%%%%%
case 'DeleteFigure'
LocalFigureDeleteFcn
%%%%%%%%%%%%%%%%
% Unused flags %
%%%%%%%%%%%%%%%%
case { 3, 9 }
sys = [];
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
if ischar(flag),
errmsg=sprintf('Unhandled flag: ''%s''', flag);
else
errmsg=sprintf('Unhandled flag: %d', flag);
end
error(errmsg);
end
% end sfunxyauto
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes(ax,varargin)
if length (ax)~=4
error(['Axes limits must be defined.'])
end
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 0;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
%
% initialize the array of sample times, note that in earlier
% versions of this scope, a sample time was not one of the input
% arguments, the varargs checks for this and if not present, assigns
% the sample time to -1 (inherited)
%
if ~isempty(varargin) > 0
ts = [varargin{1} 0];
else
ts = [-1 0];
end
% end mdlInitializeSizes
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u,flag,ax,varargin)
%
% always return empty, there are no states...
%
sys = [];
%
% 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.
%
FigHandle=GetSfunXYFigure(gcbh);
if ~ishandle(FigHandle),
return
end
%
% Get UserData of the figure.
%
ud = get(FigHandle,'UserData');
if isempty(ud.XData),
x_data = [u(1) u(1)];
y_data = [u(2) u(2)];
else
x_data = [ud.XData u(1)];
y_data = [ud.YData u(2)];
end
% plot the input lines
set(ud.XYAxes, ...
'Visible','on',...
'Xlim', ax(1:2),...
'Ylim', ax(3:4));
set(ud.XYLine,...
'Xdata',x_data,...
'Ydata',y_data,...
'LineStyle','-');
set(ud.XYTitle,'String','X Y Plot');
set(FigHandle,'Color',get(FigHandle,'Color'));
%
% update the X/Y stored data points
%
ud.XData(end+1) = u(1);
ud.YData(end+1) = u(2);
%
% autoscale the axes
%
axis(ud.XYAxes,'auto')
set(FigHandle,'UserData',ud);
drawnow
% end mdlUpdate
%
%=============================================================================
% LocalBlockStartFcn
% Function that is called when the simulation starts. Initialize the
% XY Graph scope figure.
%=============================================================================
%
function LocalBlockStartFcn
%
% get the figure associated with this block, create a figure if it doesn't
% exist
%
FigHandle = GetSfunXYFigure(gcbh);
if ~ishandle(FigHandle),
FigHandle = CreateSfunXYFigure;
end
ud = get(FigHandle,'UserData');
set(ud.XYLine,'XData',[],'YData',[]);
set(ud.XYLine,'XData',0,'YData',0);
ud.XData = [];
ud.YData = [];
set(FigHandle,'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
FigHandle=GetSfunXYFigure(gcbh);
if ishandle(FigHandle),
%
% Get UserData of the figure.
%
ud = get(FigHandle,'UserData');
set(ud.XYLine,...
'Xdata',ud.XData,...
'Ydata',ud.YData,...
'LineStyle','-');
end
% end LocalBlockStopFcn
%
%=============================================================================
% LocalBlockNameChangeFcn
% Function that handles name changes on the Graph scope block.
%=============================================================================
%
function LocalBlockNameChangeFcn
%
% get the figure associated with this block, if it's valid, change
% the name of the figure
%
FigHandle = GetSfunXYFigure(gcbh);
if ishandle(FigHandle),
set(FigHandle,'Name',get_param(gcbh,'Name'));
end
% end LocalBlockNameChangeFcn
%
%=============================================================================
% LocalBlockLoadCopyFcn
% This is the XYGraph block's LoadFcn and CopyFcn. Initialize the block's
% UserData such that a figure is not associated with the block.
%=============================================================================
%
function LocalBlockLoadCopyFcn
SetSfunXYFigure(gcbh,-1);
% end LocalBlockLoadCopyFcn
%
%=============================================================================
% LocalBlockDeleteFcn
% This is the XY Graph block'DeleteFcn. Delete the block's figure window,
% if present, upon deletion of the block.
%=============================================================================
%
function LocalBlockDeleteFcn
%
% Get the figure handle associated with the block, if it exists, delete
% the figure.
%
FigHandle=GetSfunXYFigure(gcbh);
if ishandle(FigHandle),
delete(FigHandle);
SetSfunXYFigure(gcbh,-1);
end
% end LocalBlockDeleteFcn
%
%=============================================================================
% LocalFigureDeleteFcn
% This is the XY Graph figure window's DeleteFcn. The figure window is
% being deleted, update the XY Graph block's UserData to reflect the change.
%=============================================================================
%
function LocalFigureDeleteFcn
%
% Get the block associated with this figure and set it's figure to -1
%
ud=get(gcbf,'UserData');
SetSfunXYFigure(ud.Block,-1)
% end LocalFigureDeleteFcn
%
%=============================================================================
% GetSfunXYFigure
% Retrieves the figure window associated with this S-
matlab科研助手
- 粉丝: 3w+
- 资源: 5991
最新资源
- 数电设计水箱水位检测控制系统multisim仿真+设计报告+ 水箱水位控制系统仿真功能: 1.在水箱内的不同高度安装3根金属棒,以感知水位变化情况, 液位分1,2,3档; 2.当检测到水位低于1、2档
- 风储调频,储能调频,保证真实,模型如图,保证正常使用
- Java毕业设计-基于springboot+vue的旅游管理系统设计与实现源码+数据库+部署说明+数据库设计(高分毕业设计)+项目运行截图
- comsol模拟随机裂隙注浆,浆液在多孔介质和裂隙中扩散,考虑浆液粘度时变性
- 铅酸电池失效仿真comsol
- 纯电动汽车动力经济性仿真,Cruise和Simulink联合仿真,提供Cruise整车模型和simuink策略模型,策略主要为BMS、再生制动和电机驱动策略,内含注释模型和详细解析文档,可运行
- 基于SSM框架的共享单车管理系统+spring+springMVC+Mybatis+SSM框架管理系统+毕业设计、课程设计
- 基于springboot+vue的旅游管理系统源码+数据库+部署说明+数据库设计+项目运行截图
- 改进蚁群算法+动态窗口算法全局结合局部路径规划仿真 静态路径规划算法 采用改进蚁群算法,有单独对比代码 动态实时规划 采用动态窗口算法避开未知障碍物 可自行设置地图 未知静态障碍物 移动障碍物
- 基于条件风险价值的合作型Stackerlberg博弈微网动态定价与优化 参考文献:A cooperative Stackelberg game based energy management con
- Delphi 12 控件之Delphi BS 框架 uniGUI 1.90.0.1530 + 1.90.0.1555.rar
- MATLAB代码:基于主从博弈的智能小区代理商定价策略及电动汽车充电管理 关键词:电动汽车 主从博弈 动态定价 智能小区 充放电优化 参考文档:基于主从博弈的智能小区代理商定价策略及电动汽车充电
- 基于stm32的智能药箱,全套资料,实现功能: (1)智能药箱采用stm32单片机作为主控核心 (2)NTC温度传感器实时监测药箱温度并在屏幕上显示,监测到箱内温度高于设定值时,屏显示报警信息 (
- 基于SSM框架的足球爱好者管理系统的设计与实现-Spring、SpringMVC、Mybatis-毕业设计、课程设计
- ACC自适应巡航控制(跟驰控制)CarSim Simulink联合仿真模型 上层控制器为ACC策略,下层控制器为PID控制,包含车辆逆动力学模型,效果如视频所示 文件包括一个cpar文件和一个simu
- 激光焊模拟,Fluent激光焊接流体模拟仿真,温度场仿真,激光小孔动态演变过程仿真,高斯旋转体热源,电磁力,蒸发反冲压力(面积力转化为体积力)等,可以实现外加电磁力,实现熔池流动旋转 udf 含有电
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈