Borrar filtros
Borrar filtros

Difficulty with FOR LOOP - catch 22 situation!!

1 visualización (últimos 30 días)
Mike
Mike el 12 de Ag. de 2012
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?????!!!!

Respuestas (1)

Walter Roberson
Walter Roberson el 12 de Ag. de 2012
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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by