MATLAB Answers

I am a beginner in Matlab. My problem is to update the weights after each iteration.. but I am not able to use for loop for my weights updation

1 view (last 30 days)
NITISH SINGLA
NITISH SINGLA on 20 Oct 2020
Answered: Nagasai Bharat on 23 Oct 2020
Here is my code:
clc;
clear all;
p = [-1 1; 0 0; 1 -1; 1 0; 0 1];
t = [1; 1; 1; 0; 0];
i = 0;
for i = 1:10
w(i) = [0 -1];
b(i) = 0;
a = hardlim((w(i)*p(1,:)') + b(i))
e = t(1,1) - a
if e == 0
w(i+1) = w(i);
b(i+1) = b(i);
else
w(i+1) = w(i) + e.*p(1,:)
b(i+1) = b(i) + e
end
end

  0 Comments

Sign in to comment.

Answers (1)

Nagasai Bharat
Nagasai Bharat on 23 Oct 2020
Hi,
The error you might be getting when running this script is due to the w(i) = [0 1] line. This error arises due to the case that w is would be a 2-D Matrix of size (10,2) and not a 1-D vector because we are updating in a loop and its values are row concatinated.
To resolve the issue use
w(i,:) = [0 1];

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!