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
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
2020년 3월 23일
function Weight= SGD_method(...)
alpha=0.9;
N=4;
end % <--------- DELETE THIS LINE!
for k=1:N
...
댓글 수: 2
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 Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!