필터 지우기
필터 지우기

Difficulty with FOR LOOP - catch 22 situation!!

조회 수: 1 (최근 30일)
Mike
Mike 2012년 8월 12일
I am fairly new to Matlab and |'m sincerely hoping somebody knows a solution to my Matlab problem as at the moment it seems impossible.
I have created a 'for loop' which first calculates small increments of structural displacements and then returns a value for the corresponding structural resistance during each iteration. This resistance value is dependent upon the region of a resistance-displacement graph the calculated displacement is at. There are 3 regions separated by two markers on the displacement axis (i.e. x-axis of the graph) and these markers are defined at the start of the loop.
When a particular condition is met, I want my code to update the value of the boundaries and it appears to do this. However, as the original boundaries are still in place at the start of the loop, the code then re-updates the boundaries to their previous values instead of those defined at the end of the last iteration.
Is there a way around this or is this not possible in matlab?????!!!!

답변 (1개)

Walter Roberson
Walter Roberson 2012년 8월 12일
When a "for" loop is encountered, all the values for the start, increment, and stop are recorded internally, and changes to any of those during the body of the loop will not have an effect on how the "for" loop operates.
If you need to be able to change the parameters of the loop, use a "while" loop instead.
for X = A : B : C
becomes
X = A;
while X < C
....
X = X + B;
end

카테고리

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