starbinbin_csu 发表于 2010-10-18 11:32:11

关于tic,toc的一个问题

今天在一台装有matlab7.0.1的电脑上使用tic toc的时候出现了以下的有趣现象。
rand('seed',12);
a=rand(100);
x=ones(100,1);
b=a*x;
tiaojianshu=cond(a);
tic;x1=b'/a;toc
此时显示的程序运行时间大概是0.01数量级上的。
如果清除工作间数据后将代码改成

a=rand(100);
x=ones(100,1);
b=a*x;
tiaojianshu=cond(a);
tic;x1=b'/a;toc
就会显示时间为0,请问这是怎么一回事啊?这里的rand('seed',12);到底有什么用啊?

huxw 发表于 2010-10-18 13:15:16

我运行的结果如下图。
版本:2008a

qibbxxt 发表于 2010-10-18 13:48:18

本帖最后由 qibbxxt 于 2010-10-18 13:49 编辑

至于时间是0,我没有得到这个结果,我的版本是2009a
rand('seed',12)
帮助文件中有Note   In versions of MATLAB prior to 7.7, you controlled the internal state of the random number stream used by rand by calling rand directly with the 'seed', 'state', or 'twister' keywords. That syntax is still supported for backwards compatibility, but is deprecated. For version 7.7, use the default stream as described in the @RandStream reference documentation.
rand Seeding Unique for Each Task or Lab

The random generator seed is now initialized based on the task ID for distributed jobs, or the labindex for parallel jobs (including pmode). This ensures that the random numbers generated for each task or lab are unique within a job.

liuchanghong 发表于 2010-10-20 09:22:02

是否是LZ 的显示定义字节数是短字节,请你在运行程序前,先定义long format试试。
页: [1]
查看完整版本: 关于tic,toc的一个问题