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 个)

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

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by