I want to be able to run this 100 times for a certain set of parameter values and take an average of the amount of groups that it produces.

Here is the code I have at the minute. Do I need to create another m file for this or can i do it within the function I've already created? [code]function [t seqBeliefs] = extendedHK(n, tol, adj) %extendedHK Summary of function goes here %Detailed explanation goes here beliefs = rand(n,1); seqBeliefs = beliefs; %NxT matrix converge = 0; step = 0 t = step while converge ~= 1 step = step+1; t = [t step]; A = zeros (n,n); for i=1:1:n for j=i:1:n if abs(beliefs(i) - beliefs(j)) < tol && adj(i,j)==1 A(j,i)=1; A(i,j)=1; end end end beliefs = A*beliefs./ sum(A,2); seqBeliefs = [seqBeliefs beliefs]; if sum(abs(beliefs - seqBeliefs(:,step)))<1e-12 converge = 1; end end plot(t,seqBeliefs) end %%in command window type adj=random_graph(n) then call extendedHK function %%with same n then tol value and 'adj'[/code]