I need a detailed explanation about this code
이전 댓글 표시
i started to learn matlab recently,and when i was studying about loops, one of my friend shared this code that can print a box with an X inside with the desired size

can someone provide explanation on this code?
댓글 수: 2
Jan
2017년 10월 15일
Please ask for specific details. It would be a waste of time to explain "clc", if you can read this by your own already:
help clc
채택된 답변
추가 답변 (1개)
Priyanka Akre
2020년 4월 22일
편집: Image Analyst
2022년 7월 21일
% self organizing map Kohonen
% Programmed by Ammar AL-Jodah
clc
clear all
close all
for i=1:1000
x1(i)=rand;
x2(i)=rand;
end
for j1=1:10
for j2=1:10
w1(j1,j2)=rand*(0.52-0.48)+0.48;
w2(j1,j2)=rand*(0.52-0.48)+0.48;
end
end
figure(1)
plot(x1,x2,'.b')
hold on
plot(w1,w2,'or')
plot(w1,w2,'k','linewidth',2)
plot(w1',w2','k','linewidth',2)
hold off
title('t=0');
drawnow
no=1;
do=5;
T=300;
t=1;
while (t<=T)
n=no*(1-t/T);
d=round(do*(1-t/T));
%loop for the 1000 inputs
for i=1:1000
e_norm=(x1(i)-w1).^2+(x2(i)-w2).^2;
minj1=1;minj2=1;
min_norm=e_norm(minj1,minj2);
for j1=1:10
for j2=1:10
if e_norm(j1,j2)<min_norm
min_norm=e_norm(j1,j2);
minj1=j1;
minj2=j2;
end
end
end
j1star= minj1;
j2star= minj2;
%update the winning neuron
w1(j1star,j2star)=w1(j1star,j2star)+n*(x1(i)- w1(j1star,j2star));
w2(j1star,j2star)=w2(j1star,j2star)+n*(x2(i)- w2(j1star,j2star));
%update the neighbour neurons
for dd=1:1:d
jj1=j1star-dd;
jj2=j2star;
if (jj1>=1)
w1(jj1,jj2)=w1(jj1,jj2)+n*(x1(i)-w1(jj1,jj2));
w2(jj1,jj2)=w2(jj1,jj2)+n*(x2(i)-w2(jj1,jj2));
end
jj1=j1star+dd;
jj2=j2star;
if (jj1<=10)
w1(jj1,jj2)=w1(jj1,jj2)+n*(x1(i)-w1(jj1,jj2));
w2(jj1,jj2)=w2(jj1,jj2)+n*(x2(i)-w2(jj1,jj2));
end
jj1=j1star;
jj2=j2star-dd;
if (jj2>=1)
w1(jj1,jj2)=w1(jj1,jj2)+n*(x1(i)-w1(jj1,jj2));
w2(jj1,jj2)=w2(jj1,jj2)+n*(x2(i)-w2(jj1,jj2));
end
jj1=j1star;
jj2=j2star+dd;
if (jj2<=10)
w1(jj1,jj2)=w1(jj1,jj2)+n*(x1(i)-w1(jj1,jj2));
w2(jj1,jj2)=w2(jj1,jj2)+n*(x2(i)-w2(jj1,jj2));
end
end
end
t=t+1;
figure(1)
plot(x1,x2,'.b')
hold on
plot(w1,w2,'or')
plot(w1,w2,'k','linewidth',2)
plot(w1',w2','k','linewidth',2)
hold off
title(['t=' num2str(t)]);
drawnow
end
댓글 수: 2
Priyanka Akre
2020년 4월 22일
i want explaination of this code
Image Analyst
2022년 7월 21일
Contact Ammar AL-Jodah and ask him to explain it, and put in a lot more comments like any good professional programmer would have done. There is no excuse for bad code like that.
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!