声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2715|回复: 12

如何计算实际的仿真时间

[复制链接]
发表于 2007-6-3 09:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
各位,如何计算仿真实际的运行时间呢?
我知道用tic;AAA;toc可以计算出来
我想知道实际仿真用的时间和仿真设定时间最后二者的比值,或者运行速度曲线之类的,请问有这样的吗?
回复
分享到:

使用道具 举报

发表于 2007-6-4 15:16 | 显示全部楼层
不同的系统是不一样的
没有固定的关系式的.
发表于 2007-6-4 17:13 | 显示全部楼层
不知道楼上了要实际的仿真时间做什么呢?设定一个仿真时间就可以了啊
 楼主| 发表于 2007-6-4 20:50 | 显示全部楼层
楼上的你说的那个仿真时间设定和模型的实际运行时间是不一样的,你碰见过仿真时间设定为5s,而运行了10s或者更多还没有运行完的情况?
发表于 2007-6-4 22:30 | 显示全部楼层
这个我清楚啊,仿真的实际时间有时候是很长的,这取决于你采取的算法步长,你的构建模型等等,不过他们间的关系倒是没有考虑过
发表于 2007-6-5 10:30 | 显示全部楼层
原帖由 lirui0662 于 2007-6-4 20:50 发表
楼上的你说的那个仿真时间设定和模型的实际运行时间是不一样的,你碰见过仿真时间设定为5s,而运行了10s或者更多还没有运行完的情况?

那是不是你在系统中加入了关于仿真时间的模块呢?
没遇到过,你说的这个10s是实际时间?那就很正常
如果你说的这个10s是指的右下脚那个时间那就是没遇到过。
 楼主| 发表于 2007-6-5 10:51 | 显示全部楼层
我说的10s是实际时间
楼上的知道怎么求运行速度曲线吗?
发表于 2007-6-5 17:46 | 显示全部楼层
5s的仿真时间,10s的实际时间很正常啊:@L
至于速度曲线,你想怎么求?
你莫名问了这个问题,不知道你要表达的意思呢
你是有速度输出,到示波器,觉得图不好呢?还是怎么样,matlab画图?:@L
可能没理解你这个专业名词的含义。
发表于 2007-6-5 19:10 | 显示全部楼层
原帖由 lirui0662 于 2007-6-5 10:51 发表
我说的10s是实际时间
楼上的知道怎么求运行速度曲线吗?


我觉得楼上的还是用程序画出来吧,直接把采集到的数据倒出来,用表达式写出他们的关系就可以了
 楼主| 发表于 2007-6-6 08:43 | 显示全部楼层
还好,哦瓦这里有一个程序是计算仿真设定时间,实际运行时间及其二者的比值的s函数,大家可看看,希望有用
函数用于计算仿真时间、实际运行时间、以及这两个时间的比值。这是我以前编的希望对你有用

/*****************************************************************************************************
***************function timer
***************功能说明:计算仿真时间、实际运行时间以及这两个时间的比值
***************Copyright 2004-2008
***************$Revision: 1.0 $ $Date: 2004/11/04 22:55 $ 函数版
*******************************************************************************************************/
#include <math.h>
#ifdef __cplusplus
extern "C" { // use the C fcn-call standard for all functions
#endif // defined within this scope
#define S_FUNCTION_NAME xgtimer
#define S_FUNCTION_LEVEL 2
#include "stdlib.h"
#include "stdio.h"
#include "simstruc.h"
#include "time.h"
/*====================*
* S-function methods *
*====================*/
static void mdlInitializeSizes(SimStruct *S)
{
/* See sfuntmpl_doc.c for more details on the macros below */
/***************************设置参数个数*****************************************************/

ssSetNumSFcnParams(S, 0); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */

return;
}
/***************************设置离散以及连续状态个数********************************************/

ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
/***************************设置输入端口的属性*****************************************************/
if (!ssSetNumInputPorts(S, 0)) return;
/**************************设置输出端口的属性个数**************************************************/
if (!ssSetNumOutputPorts(S, 0)) return;
/***************************设置直接反馈**************************************************/
/*
* Set direct feedthrough flag (1=yes, 0=no).
* A port has direct feedthrough if the input is used in either
* the mdlOutputs or mdlGetTimeOfNextVarHit functions.
* See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
*/

/***************************设置存储特性**************************************************/

/***************************设置采样时间个数**********************************************/
ssSetNumSampleTimes(S, 1);
/***************************设置工作向量*************************************************/
ssSetNumRWork(S, 1);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
/***************************设置过零采样的状态个数*****************************************/
ssSetNumNonsampledZCs(S, 0);
/***************************设置s函数工作选项***********************************************/
ssSetOptions(S,
SS_OPTION_WORKS_WITH_CODE_REUSE |
SS_OPTION_EXCEPTION_FREE_CODE |
SS_OPTION_USE_TLC_WITH_ACCELERATOR|SS_OPTION_USE_TLC_WITH_ACCELERATOR);
}
/*******************************************************************************************
***********************设定采样时间*********************************************************
********************************************************************************************/

static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0,0.0);
ssSetOffsetTime(S, 0, 0.0);

}

#define MDL_START /* Change to #undef to remove function */
#if defined(MDL_START)

static void mdlStart(SimStruct *S)
{ time_t sstart;
sstart=clock();
real_T xsstart;
xsstart=1.000*sstart/CLK_TCK;
ssSetRWorkValue(S,0,xsstart);
}
#endif /* MDL_START */
/*******************************************************************************************
***********************输出数据计算*********************************************************
********************************************************************************************/
static void mdlOutputs(SimStruct *S, int_T tid)
{
}

/* Function: mdlTerminate =====================================================
* Abstract:
* In this function, you should perform any actions that are necessary
* at the termination of a simulation. For example, if memory was
* allocated in mdlStart, this is the place to free it.
*/
static void mdlTerminate(SimStruct *S)
{ time_t eend;
real_T xsstart=ssGetRWorkValue(S,0);
eend=clock();
real_T T0=ssGetT(S);
//printf("%f\n",T0);
printf("******************************************************************\n");
printf("仿真时间:%f s\n",T0);

printf("程序运行时间为:%fs,合%f%小时\n",1.0*(eend/CLK_TCK-xsstart),(1.0*(eend/CLK_TCK-xsstart))/3600.0);
printf("程序运行时间为时间与仿真时间之比:%f\n",(1.00000*(eend)/CLK_TCK-xsstart)/T0);
printf("************************恭喜您本次仿真结束************************\n");
}

/*======================================================*
* See sfuntmpl_doc.c for the optional S-function methods *
*======================================================*/

/*=============================*
* Required S-function trailer *
*=============================*/

#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

#ifdef __cplusplus
} // end of extern "C" scope
#endif

评分

2

查看全部评分

 楼主| 发表于 2007-6-6 08:48 | 显示全部楼层
是参考别人的,不是我编的:loveliness:
发表于 2007-6-6 09:01 | 显示全部楼层
论坛就是互相学习的嘛,是你的还是不是你的原创都好,重要的是学会分享!
发表于 2007-6-6 11:31 | 显示全部楼层
原帖由 lirui0662 于 2007-6-6 08:48 发表
是参考别人的,不是我编的:loveliness:

如果是转贴,请补上转自哪里,这个是对人家版权的尊重哈.
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-15 08:52 , Processed in 0.076608 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表