Info

此问题已关闭。 请重新打开它进行编辑或回答。

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 次查看(过去 30 天)
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

回答(1 个)

Nagasai Bharat
Nagasai Bharat 2020-10-23
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