Filter löschen
Filter löschen

how to update the step size in my code ?

1 Ansicht (letzte 30 Tage)
kitty varghese
kitty varghese am 6 Sep. 2017
Kommentiert: KL am 8 Sep. 2017
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

Antworten (1)

KL
KL am 6 Sep. 2017
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 Kommentare
kitty varghese
kitty varghese am 8 Sep. 2017
why did you use error_val=1;
KL
KL am 8 Sep. 2017
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by