how to create a vector inside a loop?
Mostrar comentarios más antiguos
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
Respuestas (1)
madhan ravi
el 8 de Nov. de 2018
Editada: madhan ravi
el 8 de Nov. de 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 comentarios
madhan ravi
el 8 de Nov. de 2018
b is now a vector likewise adapt it to your case
ariellewin11 ariellewin11
el 8 de Nov. de 2018
madhan ravi
el 8 de Nov. de 2018
see edited answer
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!