Hello. I do not know how to change the variable b when a changed. For example:
>> a=2;
>> b=a+4;
>> while a<4
>>a=a+1
>>b
>>end
So after the loop, the result of b is still 6. So can anyone help me to change to value of b without call b=a+4 again in the loop. Thanks in advance.

 Respuesta aceptada

Guillaume
Guillaume el 2 de Nov. de 2018

0 votos

Without using OOP, this is not possible. You will have to recalculate b at each step of the loop.
While it would be possible to do it with dependent properties of a class, I wouldn't recommend doing it for such a trivial example. This is not how matlab is designed to work.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 2 de Nov. de 2018

Comentada:

el 4 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by