how to create a vector inside a loop?
이전 댓글 표시
i need to vector that saves mse final value and than plot it. how do i do that? how to create vector that saves all the answers?
if true
% code
end
function [finalW, MSE, Numiterations] = gradientDescentLinearNeuron(x, t, lr, ErrorGoal, MaxIterations)
FinalW=(2*rand(1,(size(x,1)))-1)/10;
MSE=1/(size(x,2)*((sum(t-FinalW*x).^2)));
%ErrorGoal=0.15;
%lr=0.1;
step=1;
while ((MSE>ErrorGoal)&&(step<=MaxIterations))
y=FinalW*x;
dMSEdw=-1/((size(x,2)*((t-y))*x'));
FinalW=FinalW-lr*dMSEdw;
MSE=1/(size(x,2)*((sum(t-FinalW*x).^2)));
step=step+1;
end
vectorMSE=
plot(vectorMSE,step);
end
답변 (1개)
madhan ravi
2018년 11월 8일
편집: madhan ravi
2018년 11월 8일
a=1:10; %an example
i = 1;
while i<=numel(a)
b(i) = a(i).^2; %(i) in order to avoid overwriting
i=i+1;
end
b
댓글 수: 3
madhan ravi
2018년 11월 8일
b is now a vector likewise adapt it to your case
ariellewin11 ariellewin11
2018년 11월 8일
madhan ravi
2018년 11월 8일
see edited answer
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!