Thread Subject:
??? In an assignment A(I) = B, the number of elements in B and I must be the same.

Subject: ??? In an assignment A(I) = B, the number of elements in B and I must be the same.

From: baby

Date: 11 May, 2012 16:10:10

Message: 1 of 2

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 :(

Subject: ??? In an assignment A(I) = B, the number of elements in B and I must be the same.

From: Ben

Date: 11 May, 2012 16:55:12

Message: 2 of 2

"baby" wrote in message <jojdl2$mge$1@newscl01ah.mathworks.com>...
> 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);

Look closely at the error message. The number of elements on the left side of the equation are not the same as those on the right side of the equation. Matlab can't put the data on right side into the variable on the left side because the side or indexing is wrong. When I look at these two lines:

> w1=0;

...
> w1(i)=w1(i)+dw1(i);

I immediately see that w1(i) doesn't make sense. When i=2, MATLAB tries to evaluate w1(2), which won't exist. This problem is replicated for w2 and b as well.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us