필터 지우기
필터 지우기

how to update the step size in my code ?

조회 수: 1 (최근 30일)
kitty varghese
kitty varghese 2017년 9월 6일
댓글: KL 2017년 9월 8일
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
kitty varghese
kitty varghese 2017년 9월 8일
why did you use error_val=1;
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에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by