MATLAB: How to find out the first execution of the function

MATLAB: How to find out the first execution of the function

matlab function

In a program I need to use some values for only during the first execution of the function, thereafter the execution of the function will have to take the updated values. Is there anyway I can find the execution number from Matlab command?

Best Answer

  • Add this to the beginning of the code:
    persistent number_of_executions
    if isempty(number_of_executions); number_of_executions = 0; end
    number_of_executions = number_of_executions + 1;
    Now you can test if number_of_executions == 1
  • Add a Comment

    Your email address will not be published. Required fields are marked *