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 日間)
NITISH SINGLA
NITISH SINGLA 2020 年 10 月 20 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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