Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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 visualización (últimos 30 días)
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

Respuestas (1)

Nagasai Bharat
Nagasai Bharat el 23 de Oct. de 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];

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by