matlab sizeof函数,用matlab模型生成C++代码函数的使用问题

本文讨论了将MATLAB模型转换为C++代码后遇到的问题。作者创建了一个MATLAB模型,并生成了C++代码,但在C++控制台程序中运行时,输出的变量Filter_Y.y始终为零,与Simulink仿真结果不符。作者提供了C++主函数代码以展示问题所在,寻求解决方法。
摘要由CSDN通过智能技术生成

本帖最后由 韩风 于 2016-12-9 18:04 编辑

用matlab建立如下模型:

174908vvcgobj004zq1jqt.png

QQ截图20161209171040.png (41.83 KB, 下载次数: 27)

2016-12-9 17:49 上传

然后生成如下C++代码

174909a22l07b1l2ki251k.png

QQ截图20161209174645.png (105.6 KB, 下载次数: 14)

2016-12-9 17:49 上传

有两个重要文件 Filter.h和Filter.cpp;

代码如下

/*

* Filter.h

*

* Code generation for model "Filter".

*

* Model version              : 1.3

* Simulink Coder version : 8.11 (R2016b) 25-Aug-2016

* C++ source code generated on : Fri Dec 09 15:53:37 2016

*

* Target selection: grt.tlc

* Note: GRT includes extra infrastructure and instrumentation for prototyping

* Embedded hardware selection: Intel->x86-64 (Windows64)

* Code generation objectives: Unspecified

* Validation result: Not run

*/

#ifndef RTW_HEADER_Filter_h_

#define RTW_HEADER_Filter_h_

#include

#include

#include

#include

#ifndef Filter_COMMON_INCLUDES_

# define Filter_COMMON_INCLUDES_

#include "rtwtypes.h"

#include "rtw_continuous.h"

#include "rtw_solver.h"

#include "rt_logging.h"

#endif                                 /* Filter_COMMON_INCLUDES_ */

#include "Filter_types.h"

/* Shared type includes */

#include "multiword_types.h"

#include "rt_nonfinite.h"

#include "rtGetInf.h"

/* Macros for accessing real-time model data structure */

#ifndef rtmGetFinalTime

# define rtmGetFinalTime(rtm)          ((rtm)->Timing.tFinal)

#endif

#ifndef rtmGetRTWLogInfo

# define rtmGetRTWLogInfo(rtm)         ((rtm)->rtwLogInfo)

#endif

#ifndef rtmGetErrorStatus

# define rtmGetErrorStatus(rtm)        ((rtm)->errorStatus)

#endif

#ifndef rtmSetErrorStatus

# define rtmSetErrorStatus(rtm, val)   ((rtm)->errorStatus = (val))

#endif

#ifndef rtmGetStopRequested

# define rtmGetStopRequested(rtm)      ((rtm)->Timing.stopRequestedFlag)

#endif

#ifndef rtmSetStopRequested

# define rtmSetStopRequested(rtm, val) ((rtm)->Timing.stopRequestedFlag = (val))

#endif

#ifndef rtmGetStopRequestedPtr

# define rtmGetStopRequestedPtr(rtm)   (&((rtm)->Timing.stopRequestedFlag))

#endif

#ifndef rtmGetT

# define rtmGetT(rtm)                  ((rtm)->Timing.taskTime0)

#endif

#ifndef rtmGetTFinal

# define rtmGetTFinal(rtm)             ((rtm)->Timing.tFinal)

#endif

/* Block states (auto storage) for system '' */

typedef struct {

dsp_VariableBandwidthIIRFilte_T obj; /* '/Variable Bandwidth IIR Filter' */

real_T NextOutput;                   /* '/Random Number' */

void *VariableBandwidthIIRFilter_PWOR;/* '/Variable Bandwidth IIR Filter' */

uint32_T RandSeed;                   /* '/Random Number' */

boolean_T objisempty;                /* '/Variable Bandwidth IIR Filter' */

boolean_T isInitialized;             /* '/Variable Bandwidth IIR Filter' */

} DW_Filter_T;

/* External outputs (root outports fed by signals with auto storage) */

typedef struct {

real_T y;                            /* '/y' */

} ExtY_Filter_T;

/* Parameters (auto storage) */

struct P_Filter_T_ {

real_T VariableBandwidthIIRFilter_Pass;/* Expression: 1e3

* Referenced by: '/Variable Bandwidth IIR Filter'

*/

real_T RandomNumber_Mean;            /* Expression: 0

* Referenced by: '/Random Number'

*/

real_T RandomNumber_StdDev;          /* Computed Parameter: RandomNumber_StdDev

* Referenced by: '/Random Number'

*/

real_T RandomNumber_Seed;            /* Expression: 0

* Referenced by: '/Random Number'

*/

};

/* Real-time Model Data Structure */

struct tag_RTM_Filter_T {

const char_T *errorStatus;

RTWLogInfo *rtwLogInfo;

/*

* Timing:

* The following substructure contains information regarding

* the timing information for the model.

*/

struct {

time_T taskTime0;

uint32_T clockTick0;

uint32_T clockTickH0;

time_T stepSize0;

time_T tFinal;

boolean_T stopRequestedFlag;

} Timing;

};

/* Block parameters (auto storage) */

#ifdef __cplusplus

extern "C" {

#endif

extern P_Filter_T Filter_P;

#ifdef __cplusplus

}

#endif

/* Block states (auto storage) */

extern DW_Filter_T Filter_DW;

#ifdef __cplusplus

extern "C" {

#endif

/* External outputs (root outports fed by signals with auto storage) */

extern ExtY_Filter_T Filter_Y;

#ifdef __cplusplus

}

#endif

#ifdef __cplusplus

extern "C" {

#endif

/* Model entry point functions */

extern void Filter_initialize(void);

extern void Filter_step(void);

extern void Filter_terminate(void);

#ifdef __cplusplus

}

#endif

/* Real-time Model object */

#ifdef __cplusplus

extern "C" {

#endif

extern RT_MODEL_Filter_T *const Filter_M;

#ifdef __cplusplus

}

#endif

/*-

* The generated code includes comments that allow you to trace directly

* back to the appropriate location in the model.  The basic format

* is /block_name, where system is the system number (uniquely

* assigned by Simulink) and block_name is the name of the block.

*

* Use the MATLAB hilite_system command to trace the generated code back

* to the model.  For example,

*

* hilite_system('')    - opens system 3

* hilite_system('/Kp') - opens and selects block Kp which resides in S3

*

* Here is the system hierarchy for this model

*

* '' : 'Filter'

*/

#endif                                 /* RTW_HEADER_Filter_h_ */

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/*

* Filter.cpp

*

* Code generation for model "Filter".

*

* Model version              : 1.3

* Simulink Coder version : 8.11 (R2016b) 25-Aug-2016

* C++ source code generated on : Fri Dec 09 15:53:37 2016

*

* Target selection: grt.tlc

* Note: GRT includes extra infrastructure and instrumentation for prototyping

* Embedded hardware selection: Intel->x86-64 (Windows64)

* Code generation objectives: Unspecified

* Validation result: Not run

*/

#include "stdafx.h"

#include "Filter.h"

#include "Filter_private.h"

/* Block states (auto storage) */

DW_Filter_T Filter_DW;

/* External outputs (root outports fed by signals with auto storage) */

ExtY_Filter_T Filter_Y;

/* Real-time model */

RT_MODEL_Filter_T Filter_M_;

RT_MODEL_Filter_T *const Filter_M = &Filter_M_;

/* Forward declaration for local functions */

static void VariableBandwidthIIRFilter_poly(const real_T q[2], int8_T N, real_T

p_data[], int32_T p_sizes[2]);

static void Filter_conv(const real_T A_data[], const int32_T A_sizes[2], const

real_T B_data[], const int32_T B_sizes[2], real_T C_data[], int32_T C_sizes[2]);

static void VariableBandwidthIIRFilter_newp(const real_T b_data[], const real_T

allpassnum[2], const real_T allpassden[2], int8_T M, real_T temppoly_data[],

int32_T temppoly_sizes[2]);

static void VariableBandwidthIIRFilter_tune(dsp_VariableBandwidthIIRFilte_T *obj);

static real_T VariableBandwidthIIRFilter_step(dsp_VariableBandwidthII

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值