??? In an assignment A(I) = B, the number of elements in B and I must be the same.
1 次查看(过去 30 天)
显示 更早的评论
hello,,
i need help becoz something's wrong with my code,,
please help me,,
that error show that -->>
??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in ==> w1(i)=w1(i)+dw1(i);
please help me,,
this is my homework and i must collect it tomorrow,,
my Code
p1=[0 1 0 2];
p2=[0 1 0 2];
t=[1 1 1 0];
%Weight
w1=0;
w2=0;
b=1;
teta=0;
w1new=1;
%Iteration
for j=1:3
for i=1:5
%Calculate n
n(i)=w1*p1(i)+w2*p2(i)+b;
%Calculate Output
if n(i)>teta
a(i)=1;
else
a(i)=0;
end
%calculate error value
error(i)= t(i) - a(i);
dw1(i)=error(i)*p1(i);
dw2(i)=error(i)*p2(i);
db{i}=error(i);
w1(i)=w1(i)+dw1(i);
w2(i)=w2(i)+dw2(i);
b(i)=b(i)+db{i};
end
end
disp(['P1 : ',num2str(p1)]);
i dont know what's wrong with my code,,,
please help me :(
4 个评论
Daniel Shub
2012-5-11
Over writing MATLAB functions with variables (e.g., i, j, error, and db) is bad style and can lead to all sort of problems.
采纳的回答
Image Analyst
2012-5-11
I have no idea what this does, or if my "fix" below is what you want, but at least it runs. You didn't initialize p1 and p2 to have the required 5 elements, and you didn't use w1 and w2 as matrices everywhere.
p1=[0 1 0 2 0];
p2=[0 1 0 2 0];
t=[1 1 1 0 0];
%Weight
w1 = zeros(1,5);
w2= zeros(1,5);
b= ones(1, 5);
teta=0;
w1new=1;
%Iteration
for j=1:3
for i=1:5
%Calculate n
n(i)=w1(i)*p1(i)+w2(i)*p2(i)+b(i);
%Calculate Output
if n(i)>teta
a(i)=1;
else
a(i)=0;
end
%calculate error value
error(i)= t(i) - a(i);
dw1(i)=error(i)*p1(i);
dw2(i)=error(i)*p2(i);
db{i}=error(i);
w1(i)=w1(i)+dw1(i);
w2(i)=w2(i)+dw2(i);
b(i)=b(i)+db{i};
end
end
disp(['P1 : ',num2str(p1)]);
0 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!