Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

조회 수: 6 (최근 30일)
Hello guys, this is the code taken from Nuruzzaman Faruki, from this video: https://www.youtube.com/watch?v=WoLBeWclYxo
It gives error down below. There is only 3 .m files, it is very short. Please help me. Exact code worked in his video but doesn't work in mine. I am using r2019b by the way.
This is Sigmoid.m:
function y= Sigmoid(x)
y= 1/(1+exp^(-x));
end
This is SGD_method.m:
function Weight= SGD_method(Weight, input, correct output)
alpha=0.9;
N=4;
end
for k=1:N
transposed_Input= input(k, :)';
d=correct_Output(k);
weighted_Sum=Weight*transposed_Input;
output=Sigmoid(weighted_Sum);
error= d - output;
delta= output* ( 1 - output) * error;
dWeight = alpha * delta * transposed_Input;
Weight(1)= Weight(1)+dWeight(1);
Weight(2)=Weight(2)+dWeight(2);
Weight(3)=Weight(3)+dWeight(3);
end
end
And this is the Training.m:
input=[0 0 1;
0 1 1;
1 0 1;
1 1 1;
];
correct_Output=[0
0
1
1
];
Weight=2*rand(1, 3) - 1;
for epoch = 1:10000
Weight= SGD_method(Weight, input, correct_Output);
end
It gives this error:
>> Training
Error: File: SGD_method.m Line: 5 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "SGD_method".)
Error in Training (line 13)
Weight= SGD_method(Weight, input, correct_Output);
  댓글 수: 1
Stephen23
Stephen23 2020년 3월 23일
Your code is badly aligned. Badly aligned code is one way that beginners hide basic bugs and errors in their code (e.g. the cause of the error in your code). You should align your code consistently, it would make it much easier to spot basic errors like this one.
I recommend using the default MATLAB Editor settings. You can also align existing code using the Editor: select the code text, press ctrl+i.

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2020년 3월 23일
function Weight= SGD_method(...)
alpha=0.9;
N=4;
end % <--------- DELETE THIS LINE!
for k=1:N
...
  댓글 수: 2
Mahmut Dönmez
Mahmut Dönmez 2020년 3월 24일
Thanks, it stopped giving errors but in the video it created a .mat file but it didn't do for me. Why is that? Our teachers won't help at all, neither they even taught us in the first place.
Steven Lord
Steven Lord 2020년 3월 24일
There's no call to save anywhere in the code you posted, so I would have been surprised had it created a MAT-file.
It sounds a bit like you're trying to learn MATLAB by watching videos on YouTube. If that's the case, might I suggest that you take the free two hour MATLAB Onramp tutorial available from the Tutorials item on the Support section of this website? Click on the link Support at the top of this page then go to Tutorials. The MATLAB Onramp tutorial is an interactive course designed to teach you the fundamentals of working with MATLAB

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by