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

📄 getsig.c

📁 模糊神经网络采用matlab编程 o install NEFCON follow these steps: 1. Unpack the tar file NEFCON.TAR into your MA
💻 C
字号:
/*  
 * GETSIG    Get a signal value from the workspace  
 *           use in conjunction with putsig 
 *  
 *           Syntax:  [sys, x0] = getsig(t,x,u,flag,lb,ub,x0)  
 *  
 * Gary Levenson 6-8-1994  
 * 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 getsig 
  
/*  
 * 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, 0);      /* number of inputs */  
    ssSetNumOutputs(       S, width);      /* number of outputs */  
    ssSetDirectFeedThrough(S, 0);      /* 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)  
{  
	int width;  
	Matrix *pm;

        width = mxGetPr(WIDTH)[0];         
	if  (((pm = mexGetMatrixPtr((char *)ssGetIWork(S))) == NULL) ||
	                                    (mxGetM(pm)*mxGetN(pm) != width)) {  
/*
	         mexPrintf("??? Warning: signal not available in workspace.\n"); 
	         mexPrintf("Cut and then paste the GOTO block to ensure syncrhonicity \nand verify size and name information\n");
*/
	    }  
	    else { 
	        double *pr;
	        pr = mxGetPr(pm);
	        memcpy(y,pr,width*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(S)  
    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 + -