Start of trail End of trail navigation bar

Table of Contents

instance

Returns a numeric string that increments each time this function is called.

Syntax

s = instance          % Returns a new instance number with 10 digits
s = instance(n)       % Returns a new instance number with n digits
s = instance('reset') % Resets the instance counter and returns 1
instance reset        % Resets the instance counter
    

Description

Returns a string containing a number. This number is incremented each time the function is called.

By default, the numeric string returned has 10 digits - the number is padded on the left with zeros to make up the 10 digits. However, the number of digits may be passed as an argument. For example, instance(3) would return a string with three digits instead of ten.

The number increments from 1 at the start of the MATLAB session and continues to increment every time the function is called, even if the MATLAB workspace is cleared. To reset the count back to 1, issue the instance reset command.

This function is typically used with the %{expr} format specifier in various locations. For example, using the string "data%{instance(3)}.mat" as the filename parameter of the To Host File block results in a new data file being generated each time the model is run, with names such as data001.mat, data002.mat, etc.

Parameters

This function has no parameters.

Outputs

s

The string containing the current instance counter value. The number of digits in the string is 10 unless a different number of digits is passed as an argument.

Examples

s = instance(3)  % Returns a 3 digit number
s = instance(3)  % Returns the next 3 digit number in sequence
instance reset   % Resets the count to 1
    

See Also

 

navigation bar