how to create a vector inside a loop?
Show older comments
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
Answers (1)
madhan ravi
on 8 Nov 2018
Edited: madhan ravi
on 8 Nov 2018
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 Comments
madhan ravi
on 8 Nov 2018
b is now a vector likewise adapt it to your case
ariellewin11 ariellewin11
on 8 Nov 2018
madhan ravi
on 8 Nov 2018
see edited answer
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!