how to update the step size in my code ?

1 次查看(过去 30 天)
This is a dummy program. I want to update the values of stepsize1 and stepsize2 such that my error<0.5. I have coded something but I'm unable to update the new value.
if true
A=[25 30 47 58;11 25 87 98;77 44 85 23;97 48 25 14];
B=[1 5;5 1;7 7;9 8];
C=[74 2 11 7;5 6 9 9];
stepsize1=1;
stepsize2=1;
B1=stepsize1*B;
C1=stepsize2*C;
W=B1*C1;
error=pdist2(A,W,'euclidean');
if error<0.5
break
else stepsize1=stepsize1+0.1;
stepsze2=stepsize2+0.1;
end
end

回答(1 个)

KL
KL 2017-9-6
Something like this??
A=[25 30 47 58;11 25 87 98;77 44 85 23;97 48 25 14];
B=[1 5;5 1;7 7;9 8];
C=[74 2 11 7;5 6 9 9];
stepsize1=0.9;
stepsize2=0.9;
error_val = 1; %dummy
while error_val>0.5
stepsize1=stepsize1+0.1;
stepsze2=stepsize2+0.1;
B1=stepsize1*B;
C1=stepsize2*C;
W=B1*C1;
error_val=pdist2(A,W,'euclidean')
end
  2 个评论
KL
KL 2017-9-8
while loop checks condition (in this case, error_val>0.5) at the start, so we just need something more than 0.5 so the loop is executed at least once to calculate the actual value of the error_val. Then the loop is repeated until this condition becomes false.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Functions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by