Azzera filtri
Azzera filtri

how to update the step size in my code ?

1 visualizzazione (ultimi 30 giorni)
kitty varghese
kitty varghese il 6 Set 2017
Commentato: KL il 8 Set 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

Risposte (1)

KL
KL il 6 Set 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 Commenti
kitty varghese
kitty varghese il 8 Set 2017
why did you use error_val=1;
KL
KL il 8 Set 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.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by