lundi 8 juillet 2019

Check if only once

In a MATLAB-function the following code is used:

function stuff()

  if a == 2

    do1();

  else

    do2();

  end
end

This code is placed inside a simulation-loop and gets called 1000 times or more per second. The if-statement does only matter in the first call of the function, after that either do1 or do2 are used, the variable a will not change any more.

How do I prevent to waste processing time with this if-statement? Basically, how do I tell Matlab, to not check the if-statement any more, and just call the one function, that gets selected in the first call to stuff?

Aucun commentaire:

Enregistrer un commentaire