⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 putsig.c

📁 模糊神经网络采用matlab编程 o install NEFCON follow these steps: 1. Unpack the tar file NEFCON.TAR into your MA
💻 C
字号:
/*   

 * PUTSIG   Puts a signal to the workspace to act as a GOTO block   

 *          To be used in conjunction with GETSIG

 *   

 *           Syntax:  [sys, x0] = putsig(t,x,u,flag,width,'name')   

 *  

 * Gary Levenson  6-8-94   

 * Copyright (c) 1990-94 by The MathWorks, Inc.   

 * All Rights Reserved   

 */   

     



   

/*   

 * The following #define is used to specify the name of this S-Function.   

 */   

   

#define S_FUNCTION_NAME putsig   

   

/*   

 * need to include simstruc.h for the definition of the SimStruct and   

 * its associated macro definitions.   

 */   

#include <stdio.h>   

#include <string.h>  

#include "simstruc.h"   

#include "mex.h"   

  

#define NUMINPUTARGS    2  

#define WIDTH           ssGetArg(S,0)  

    

  

/*   

 * mdlInitializeSizes - initialize the sizes array   

 *   

 * The sizes array is used by SIMULINK to determine the S-function block's   

 * characteristics (number of inputs, outputs, states, etc.).   

 */   



  

static void mdlInitializeSizes(SimStruct *S)   

{  

   

    int width;

       

    if (ssGetNumArgs(S) != 2) {  

	char err_msg[256];  

	sprintf(err_msg,"Wrong number of input arguments passed to S-function MEX-file.\n"  

		"%d input arguments were passed in when expecting %d input arguments.\n", ssGetNumArgs(S) + 4, NUMINPUTARGS + 4); 

	mexErrMsgTxt(err_msg);  

	return;  

    }  

    width = mxGetPr(WIDTH)[0];  

    ssSetNumContStates(    S, 0);      /* number of continuous states */   

    ssSetNumDiscStates(    S, 0);      /* number of discrete states */   

    ssSetNumInputs(        S, width);  /* number of inputs */   

    ssSetNumOutputs(       S, 0);      /* number of outputs */   

    ssSetDirectFeedThrough(S, 1);      /* direct feedthrough flag */   

    ssSetNumSampleTimes(   S, 1);      /* number of sample times */   

    ssSetNumInputArgs(     S, NUMINPUTARGS);      /* number of input arguments */   

    ssSetNumRWork(         S, 0);      /* number of real work vector elements */   

    ssSetNumIWork(         S, 20*sizeof(int)/sizeof(char));      /* number of integer work vector elements */   

    ssSetNumPWork(         S, 0);      /* number of pointer work vector elements */  

       

}   

   

/*   

 * mdlInitializeSampleTimes - initialize the sample times array   

 *   

 * This function is used to specify the sample time(s) for your S-function.   

 * If your S-function is continuous, you must specify a sample time of 0.0.   

 * Sample times must be registered in ascending order.   

 */   

   

static void mdlInitializeSampleTimes(SimStruct *S)   

{   

    /*   

     * This a purely continuous block, so I set the sample time   

     * to 0.0.   

     */   

       

    ssSetSampleTimeEvent(S, 0, 0.0);   

    ssSetOffsetTimeEvent(S, 0, 0.0);   

}   

   

/*   

 * mdlInitializeConditions - initialize the states   

 *   

 * In this function, you should initialize the continuous and discrete   

 * states for your S-function block.  The initial states are placed   

 * in the x0 variable.  You can also perform any other initialization   

 * activities that your S-function may require.   

 */   

   

static void mdlInitializeConditions(double *x0, SimStruct *S)   

{   

    Matrix *pm;

    

    pm = ssGetArg(S,1);

    mxGetString(pm,(char *)ssGetIWork(S), mxGetN(pm)+1);    

}   

   

/*   

 * mdlOutputs - compute the outputs   

 *   

 * In this function, you compute the outputs of your S-function   

 * block.  The outputs are placed in the y variable.   

 */   

   

static void mdlOutputs(double *y, double *x, double *u, SimStruct *S, int tid)   

{  

    Matrix *pm;

    double *pr; 

/* 

 *  If the matrix has not been created, or the number of columns of u is different from

 *  the columns of the matrix in the workspace, write it to the workspace. Otherwise, write

 *  the input to the real part of the matrix in the workspace.

 */

    

  if  (  ((pm = mexGetMatrixPtr((char *)ssGetIWork(S))) == NULL) || 

                                        (mxGetM(pm)*mxGetN(pm) != ssGetNumInputs(S)))

     mexPutFull((char *)ssGetIWork(S),1, mxGetPr(WIDTH)[0], u,NULL);

  else {

    /*mexPrintf("In else\n");*/

    pr = mxGetPr(pm);

    /* do memcpy here */    

    memcpy(pr,u, mxGetPr(WIDTH)[0]*sizeof(double));

   }

}   

   

/*   

 * mdlUpdate - perform action at major integration time step   

 *   

 * This function is called once for every major integration time step.   

 * Discrete states are typically updated here, but this function is useful   

 * for performing any tasks that should only take place once per integration   

 * step.   

 */   

   

static void mdlUpdate(double *x, double *u, SimStruct *S, int tid)   

{   

}   

   

/*   

 * mdlDerivatives - compute the derivatives   

 *   

 * In this function, you compute the S-function block's derivatives.   

 * The derivatives are placed in the dx variable.   

 */   

   

static void mdlDerivatives(double *dx, double *x, double *u, SimStruct *S, int tid)   

{   

       

}   

   

/*   

 * mdlTerminate - called when the simulation is terminated.   

 *   

 * In this function, you should perform any actions that are necessary   

 * at the termination of a simulation.  For example, if memory was allocated   

 * in mdlInitializeConditions, this is the place to free it.   

 */   

   

static void mdlTerminate(SimStruct *S)   

{   

	   

}   

   

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */   

#include "simulink.c"      /* MEX-file interface mechanism */   

#else   

#include "cg_sfun.h"       /* Code generation registration function */   

#endif                 



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -