如何在M文件中用clock的值 matlab

[复制链接]
查看11 | 回复1 | 2011-3-19 06:18:55 | 显示全部楼层 |阅读模式
我需要在M文件中保存,simulink开始执行到调用该段M文件之前的所有时间的点,并将这些点保存在数组中。
或者解决[y,x]=lsim(num,den,data.y,t)这个语句的时间问题。时间t为simulink开始执行到调用该段M文件之前的所有时间的点。
万分感谢!!!!
回复

使用道具 举报

千问 | 2011-3-19 06:18:55 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">可以用clock()函数, 返回自程序开始运行所经过的时间,返回值为clock_t , 转换返回值为秒, 返回值除以CLOCKS_PER_SEC.

#include stdio.h
#include time.h
int c = 0;
int main(int argc, char *argv[])
{

clock_t a =clock();

for(int i=0; i9000 ; i )
{
for(int j=0; j9000 ; j )
{
c;
}

c -= 9000;
}

clock_t b =clock();

long doubled = b - a;
long doubletime = d/CLOCKS_PER_SEC;

printf(\"time:%g\", time);

return 0;
}

这个是微软的程序

#include stdio.h
#include stdlib.h
#include time.h

void sleep( clock_t wait );

void main( void )
{
long
i = 600000L;
clock_t start, finish;
doubleduration;

/* Delay for a specified time. */
printf( \"Delay for three seconds\\n\" );
sleep( (clock_t)3 * CLOCKS_PER_SEC );
printf( \"Done!\\n\" );

/* Measure the duration of an event. */
printf( \"Time to do %ld empty loops is \", i );
start = clock();
while( i-- )

;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( \"%2.1f seconds\\n\", duration );
}

/* Pauses for a specified number of milliseconds. */
void sleep( clock_t wait )
{
clock_t goal;
goal = wait clock();
while( goalclock() )

;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行