You have the value of x and y as integer constants. If you take these as vectors, the length of these variables is 1.
Inside the for-loop of your code above, you are iterating over x and y from i = 1 to i = 30 (since, n = 30). Thus, you get the following error:
Index exceeds matrix dimensions.
I think you meant to iterate over the matrix P which you create with the data from your text file. You should do the following in this case:
load project2trial.txt
N = length(project2trial);
x=1;
y=2;
P = project2trial(1:N, [x;y]);
w1=1.8; w2=-0.3; b=-1;a=0.5; n=30;
for j=1:10000
R=[];
for i=1:n
s=w1*P(i,1)+w2*P(i,2)+b;
if s>=0
cc=1;
else
cc=0;
end
end
end
If not this then your requirement must be only constant values of x and y. Thus, you will have to do the following:
load project2trial.txt
N = length(project2trial);
x=1;
y=2;
P = project2trial(1:N, [x;y]);
w1=1.8; w2=-0.3; b=-1;a=0.5; n=30;
for j=1:10000
R=[];
for i=1:n
s=w1*x+w2*y+b;
if s>=0
cc=1;
else
cc=0;
end
end
end