S-Fuction练习
Posted franksimon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了S-Fuction练习相关的知识,希望对你有一定的参考价值。
题目一:
该块输入一个标量信号,将信号加倍,然后输出到一个 scope进行显示。
function [sys,x0,str,ts] = timestwo(t,x,u,flag) % Dispatch the flag. The switch function controls the calls to % S-function routines at each simulation stage. switch flag, case 0 [sys,x0,str,ts] = mdlInitializeSizes; % Initialization case 3 sys = mdlOutputs(t,x,u); % Calculate outputs case { 1, 2, 4, 9 } sys = []; % Unused flags otherwise error([‘Unhandled flag = ‘,num2str(flag)]); % Error handling end; % End of function timestwo.
%==============================================================
% Function mdlInitializeSizes initializes the states, sample
% times, state ordering strings (str), and sizes structure.
%==============================================================
function [sys,x0,str,ts] = mdlInitializeSizes
% Call function simsizes to create the sizes structure.
sizes = simsizes;
% Load the sizes structure with the initialization information.
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs= 1;
sizes.NumInputs= 1;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
% Load the sys vector with the sizes information.
sys = simsizes(sizes);
%
x0 = []; % No continuous states
%
str = []; % No state ordering
%
ts = [-1 0]; % Inherited sample time
% End of mdlInitializeSizes.
%==============================================================
% Function mdlOutputs performs the calculations.
%==============================================================
function sys = mdlOutputs(t,x,u)
sys = 2*u;
% End of mdlOutputs.
以上是关于S-Fuction练习的主要内容,如果未能解决你的问题,请参考以下文章
Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段