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

📄 arymimai.c

📁 Proakis《contemporarycommunication systems using matlab》matlab源代码
💻 C
字号:
/*
 * ARYMIMAI  array minimum/maximum index computation. 
 *
 *           Syntax:  [sys, x0] = arymimai(t,x,u,flag,Func)
 *                      where Func is the string which could be min or max.
 *                      There is one output which is the index number range
 *                      from 0 to M-1 where M is the input vector size.
 *                      The input could be any real data.
 * Wes Wang 5/11/94
 * Copyright (c) 1994-96 The MathWorks, Inc.
 * All Rights Reserved
 * $Revision: 1.1 $  $Date: 1996/04/01 19:01:58 $
 */

/* specify the name of this S-Function. */
#define S_FUNCTION_NAME arymimai

/* Defines for easy access  the matrices which are passed in */
#define NUM_ARGS    1
#define FUN_NAME    ssGetArg(S, 0)

/* include simstruc.h for the definition of the SimStruct and macro definitions. */
#include <math.h>
#ifdef MATLAB_MEX_FILE
#include <stdio.h>
#endif
#include <string.h>
#include "simstruc.h"

/*
 * mdlInitializeSizes - initialize the sizes array
 */

static void mdlInitializeSizes (S)
    SimStruct *S;
{
  ssSetNumContStates(    S, 0); /* number of continuous states */
  ssSetNumDiscStates(    S, 0);       /* number of discrete states */
  ssSetNumInputs    (    S, -1);   /* number of inputs */
  ssSetNumOutputs   (    S, 1);   /* number of outputs */
  ssSetDirectFeedThrough(S, 1);       /* direct feedthrough flag */
  ssSetNumSampleTimes(   S, 1);       /* number of sample times */
  ssSetNumInputArgs(     S, NUM_ARGS);/* number of input arguments */
  ssSetNumRWork(         S, 0);       /* number of real work vector elements */
  ssSetNumIWork(         S, 0);      /* 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(S)
    SimStruct *S;
{
  ssSetSampleTimeEvent(S, 0, 0.0);
  ssSetOffsetTimeEvent(S, 0, 0.0);
}

/*
 * mdlInitializeConditions - initialize the states
 * Initialize the states, Integers and real-numbers
 */

static void mdlInitializeConditions(x0, S)
     double *x0;
     SimStruct *S;
{
}

/*
 * 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(y, x, u, S, tid)
     double *y, *x, *u;
     SimStruct *S;
     int tid;
{
  int     inSize, i, ind;
  double  tmp;
  char    funct[3];
  
  for (i=0; i < 3; i++)
    funct[i] = (char)mxGetPr(FUN_NAME)[i];
  inSize = ssGetNumInputs(S);
  tmp = u[0];
  ind = 0;
  if (inSize > 1) {
    if (funct[1] == 'a') {
      for (i=1; i<inSize; i++) {
        if (tmp < u[i]) {
	  tmp = u[i];
	  ind = i;
	}
      }
    }
    if (funct[1] == 'i') {
      for (i=1; i<inSize; i++) {
        if (tmp > u[i]) {
	  tmp = u[i];
	  ind = i;
	}
      }
    }
  }
  y[0] = (double)ind;
  if (funct[2] == 'v')
    y[0] = tmp;
}

/*
 * 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(x, u, S, tid)
    double *x, *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(dx, x, u, S, tid)
    double *dx, *x, *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 + -