??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Show older comments
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 Comments
Daniel Shub
on 11 May 2012
That is not the error I get
??? Attempted to access w1(2); index out of bounds because numel(w1)=1.
Thomas
on 11 May 2012
Daniel is correct.. The error is that w1(2) cannot be accessed because you have only put w1=0 (i.e. only one element and you are trying to access it as an array..
Daniel Shub
on 11 May 2012
Over writing MATLAB functions with variables (e.g., i, j, error, and db) is bad style and can lead to all sort of problems.
Greg Heath
on 15 Jul 2012
Why are you using loops when your result can be obtained by matrix operations?
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!