Code covered by the BSD License  

Highlights from
Numerical Computing with Simulink, Vol. 1

image thumbnail
from Numerical Computing with Simulink, Vol. 1 by Richard Gran
This sequel to Numerical Computing with MATLAB explores the mathematics of simulation.

Test_Noise_Models.m
%  This m-file runs the noise simulation models:
%  
%   Discrete_Digital_Noise                           
%   Discrete_Digital_Noise1                          
%   Discrete_Digital_Noise2                            
%   Discrete_Digital_Noise3
% 
%  using the MATLAB sim command with tic and toc before and after the
%  simulation to evaluate the total time taken to exceute the models.  The
%  resulting simulation times are stored as t0,t1 t2 and t3.  

for j =1:10
    for i = 0:3
        %  Create a string that will evaluated to:
        %        tic; sim('test"i"); t"i"=toc
        %  Where "i" evaluates to 0,1,2, or 3 from the command num2str(i)
        %  (this command converts the floating pt. number i to a string)
        str = ['tic; sim(''test' num2str(i) '''); t' num2str(i) '(' num2str(j) ')=toc;'];
        eval(str)
    end
end

% Averages
Avgsim0 = mean(t0)
Avgsim1 = mean(t1)
Avgsim2 = mean(t2)
Avgsim3 = mean(t3)

Contact us at files@mathworks.com