clear;
%%%%%%%%%%%%%%%%%%%%%%%%%% Reading input %%%%%%%%%%%%%%%%%%%
myfid=-1;
while(myfid<0)
myfile=input('Please enter input file name: ','s');
myfid=fopen(myfile,'r');
end
mybuf=fscanf(myfid,'%f,%f');
fclose(myfid);
for i=1:size(mybuf)/2
p(i,1)=mybuf(2*i-1);p(i,2)=mybuf(2*i);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Let's assume p %%%%%%%%%%%%%%%%%%%
%for j=1:10
%for i=1:10
% p(i+(j-1)*10,1)=i*0.1;p(i+(j-1)*10,2)=j*0.1;
%end
%end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%% Initializing %%%%%%%%%%%%%%%%%%%%%%%%
mysize=size(p);mysize=mysize(1);
n=input('Enter size of the network: ');
mytotal=input('Enter total number of epoch: ');
mypause=input('Enter number of epoch between frame: ');
disp(n);disp(mytotal);disp(mypause);
%pause;
%mypause=100;
%mytotal=1000;
mycount=1;
M=moviein(mytotal/mypause);
minmin=min(min(p));maxmax=max(max(p));
%%%%%%%%%% initialize weights
%n=3;
A=rand(n);
B=rand(n); %%% w1=(A11,B11)
figure;hold;
%%%%%%%% Ploting First frame...
for i=1:n
temp1=A(i,:);
temp2=B(i,:);
plot(temp1,temp2);
end
for i=1:n
temp1=A(:,i);
temp2=B(:,i);
plot(temp1,temp2);
end
plot(A,B,'o');
axis([minmin,maxmax,minmin,maxmax]);
M(:,mycount)=getframe;
clf;
%%%%%%%%%%%%%%%%%%%%%% Start Simulation %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% Main loop
for m=1:mytotal
%%%%%%%%%%%%%%%%%%%% One epoch
for s=1:mysize
%%%%%%%%% Competing (using distance)
compete=(p(s,1)-A).*(p(s,1)-A)+(p(s,2)-B).*(p(s,2)-B);
mymin=min(min(compete));
for x=1:n
for y=1:n
if compete(x,y)==mymin break; end
end
if compete(x,y)==mymin break; end %%now min is at x,y
end
%%%%%%%%% Adjusting (winning node at x,y)
for i=1:n
for j=1:n
mymax=sqrt((i-x)^2+(j-y)^2);
myalpha=(0.001)*exp(-m/mytotal)/exp(mymax^2/2);
A(i,j)=A(i,j)+myalpha*(p(s,1)-A(i,j));
B(i,j)=B(i,j)+myalpha*(p(s,2)-B(i,j));
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% End one epoch
end
disp(m);
if m==mycount*mypause
clf;hold;
%%%%%%%% Ploting
for i=1:n
temp1=A(i,:);
temp2=B(i,:);
plot(temp1,temp2);
end
for i=1:n
temp1=A(:,i);
temp2=B(:,i);
plot(temp1,temp2);
end
plot(A,B,'o');axis([minmin,maxmax,minmin,maxmax]);
M(:,mycount)=getframe;
mycount=mycount+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
movie(M,2,2);
               (
geocities.com/vienna/7079)                   (
geocities.com/vienna)