如何测量创建对象的时间matlab

how to measure time to create object matlab

我正在尝试测量构造函数创建已在其自身 class 中定义的对象所需的时间。

我如何在 matlab 中执行此操作?

非常感谢。

这是 class

classdef randv
%To create a random vector that fit into the basics requirement
%   Random vector that fits into basic requirements and
%   compute the froud number

properties(GetAccess=public, SetAccess=protected)
    x1
    x2
    x3
    x4
    valid
    fr
    d_i
    dd_i
    delta_i
end

methods
    function j=randv()
        x1=(75-50).*rand(1)+50;
        x2=(15-10).*rand(1)+10;
        x3=(7.7-5.7).*rand(1)+5.7;
        x4=(24.2-18.1).*rand(1)+18.1;

        while ((x1/x2 >= 4.7 && x1/x2 <= 6.5 && x2/x3<= 2) == 0) 
            x1=(75-50).*rand(1)+50;
            x2=(15-10).*rand(1)+10;
            x3=(7.7-5.7).*rand(1)+5.7;
            x4=(24.2-18.1).*rand(1)+18.1;

        end

            j.x1=x1;
            j.x2=x2;
            j.x3=x3;
            j.x4=x4;
            j.valid=1;
            j.fr=5.15/sqrt(9.81*j.x1);
            j.d_i=x2/x3;
            j.dd_i=x1/x4;
            j.delta_i= 1*0.72*x1*(x2^2/x3);

    end

end

结束

谢谢

围绕构造函数的调用写一个tic toc

试试 tictoc:

tic
my_obj = randv();
toc