## I've created MATLAB code here that produces a graph and depending on parameters (some random) converges to a different a

You can post your problem related to MATLAB Projects here. We will try our best to help you out.
Charles
Posts: 19
Joined: Sat Feb 18, 2017 7:12 am

### I've created MATLAB code here that produces a graph and depending on parameters (some random) converges to a different a

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: Select all

``````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'``````