hacaoideas
hacaoideas

Reputation: 115

how to measure time to create object matlab

I'm trying to measure the time required for a constructor to create an object already defined in its own class.

How can i do this in matlab?

Thanks a lot.

here's the 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

end

Thank you

Upvotes: 1

Views: 52

Answers (2)

scmg
scmg

Reputation: 1894

Try tic and toc:

tic
my_obj = randv();
toc

Upvotes: 3

Knipser
Knipser

Reputation: 347

Write a tic toc around the call of the constructor.

Upvotes: 0

Related Questions