필터 지우기
필터 지우기

for loop index variable change inside the loop[

조회 수: 28 (최근 30일)
RAKESH KUMAR TOTA
RAKESH KUMAR TOTA 2022년 1월 7일
댓글: Rik 2022년 1월 11일
I have a very basic coding question but little tricky . Any help would be appreciated
The question follows :
a = [ 3 7 2 6]
x = large size vector
for i = a
for j = x(a,:)
... expression
.. expression
c = find (a > j)
if c ~0
a (c )= a (c) -1;
end
end
end
But for loop index i not changing according to change in variable a. As i came to know from mathwork community it can't be changes . Could some one assit me how to approach this problem.
  댓글 수: 5
RAKESH KUMAR TOTA
RAKESH KUMAR TOTA 2022년 1월 11일
Thank you it served purpose how to accpet both answers @KSSV and @Simon Chan
Rik
Rik 2022년 1월 11일
Your comment is a bit confusing to me. Did KSSV and Simon solve the problem for you? They posted comments (not answers), so you can't mark them as accepted answer.

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

답변 (1개)

Rik
Rik 2022년 1월 7일
Once a for loop has started you can no longer change the expression it is based on.
You will have to rewrite your for loop as 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