how to change from for loop to while loop

조회 수: 5 (최근 30일)
amjad hammad
amjad hammad 2021년 10월 17일
편집: James Tursa 2021년 10월 17일
hi can any one tell me how to change this loop to while loop
% Modify the simulation code to include analysis of multiple errors, that
% cannot be decoded by the specified code. Find how many error words cannot
% be corrected.
ueCount = 0 ;
UncorrectableErrorwords = 0 ;
for i = 1:length(Errors)
if(sum(Errors(:,i)) > tcor)
ueCount = ueCount + 1;
end
end
it tried do it but i dont know where is the problem
ueCount = 0 ;
UncorrectableErrorwords = 0 ;
i = 1;
while i<=length(Errors)
if(sum(Errors(:,i)) > tcor)
ueCount = ueCount + 1;
end
end

답변 (1개)

James Tursa
James Tursa 2021년 10월 17일
편집: James Tursa 2021년 10월 17일
You never change i or Errors within the while loop, so how is the loop ever supposed to exit? Maybe you want to add this line:
i = i + 1;
That being said, it is not clear to me why you are changing from a for loop to a while loop.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by