is 'continue' in 'c' language similar in MATLAB??

i am changing my code of c language in to matlab .but its gives infinite loop in Matlab during use 'continue' statement?
what is the problem? is there any other alternate of 'continue' statement?

댓글 수: 4

Jan
Jan 2013년 4월 6일
Without seeing the code, we cannot guess what's going on. Please, kpreet, think twice: Do you really think that a useful answer is possible based on this level of information?
preet
preet 2013년 4월 6일
my code is too long dear...thats why i did not paste here.
preet
preet 2013년 4월 6일
편집: preet 2013년 4월 6일
let me know both continue statements are same in matlab and c language
preet
preet 2013년 4월 6일
편집: preet 2013년 4월 6일
for i=istart:n
if pnewperCube(i)<=tm
flag=1;
ppnewQR1=pnewQR(i);ppnewQG1=pnewQG(i);ppnewQB1=pnewQB(i);
ppnewperR1=pnewperR(i); ppnewperG1=pnewperG(i);ppnewperB1=pnewperB(i);
jmin=1;
while j<=n
if j==i
continue;
end
ppnewQR2=pnewQR(j);ppnewQG2=pnewQG(j);ppnewQB2=pnewQB(j);
dist2=abs(ppnewQR1-ppnewQR2)+abs(ppnewQG1-ppnewQG2)+abs(ppnewQB1-ppnewQB2);
if distmin>dist2
distmin=dist2;
jmin=j;
end
j=j+1;
end %j loop
ppnewQR2=pnewQR(jmin);ppnewQG2=pnewQG(jmin);ppnewQB2=pnewQB(jmin);
ppnewperR2=pnewperR(jmin);ppnewperG2=pnewperG(jmin);ppnewperB2=pnewperB(jmin);
XrP=floor(((ppnewQR1*ppnewperR1)+(ppnewQR2*ppnewperR2))/(ppnewperR1+ppnewperR2));
XgP=floor(((ppnewQG1*ppnewperG1)+(ppnewQG2*ppnewperG2))/(ppnewperG1+ppnewperG2));
XbP=floor(((ppnewQB1*ppnewperB1)+(ppnewQB2*ppnewperB2))/(ppnewperB1+ppnewperB2));
. . . . .
end
end

댓글을 달려면 로그인하십시오.

 채택된 답변

Friedrich
Friedrich 2013년 4월 6일
편집: Friedrich 2013년 4월 6일

1 개 추천

Hi,
yes continue in MATLAB is the same as in C. However when I look at that while loop:
while j<=n
if j==i
continue;
end
this can`t even work in C. If j == i you will hit an endless loop because j never changes. Maybe you are missing to increment j before the continue statement?

댓글 수: 2

preet
preet 2013년 4월 6일
thanx for reply. but dear friedrich i already incremented j, problem is something else.
Cedric
Cedric 2013년 4월 6일
편집: Cedric 2013년 4월 6일
No, the problem is precisely here. You increment j after the conditional statement, so your code is looping between the WHILE and the CONTINUE, without ever incrementing j. It would be the exact same in C, unless you had a j++ in either condition.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by