Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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 Ansicht (letzte 30 Tage)
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

Antworten (1)

Nagasai Bharat
Nagasai Bharat am 23 Okt. 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];

Community Treasure Hunt

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

Start Hunting!

Translated by