Main Content

simscape.logging.timestamp

Determine whether simulation log is current or stale

Since R2021a

Description

simscape.logging.timestamp(node) returns the model timestamp associated with the node, node. Before you call this function, you must have the simulation log variable associated with the simlog object in your current workspace. To create the simulation log variable, simulate the model with data logging turned on, or load a previously saved variable from a file.

You can determine whether the simlog object in your workspace is current or stale by comparing its timestamp with the model timestamp.

example

Examples

collapse all

You can determine whether the simlog object in your workspace is current or stale by comparing its timestamp with the model timestamp.

Open the Permanent Magnet DC Motor example model, which has data logging enabled, and run the simulation to create the simulation log variable simlog_PermanentMagnetDCMotor (as specified by the Workspace variable name model configuration parameter) in your current workspace:

openExample('simscape/PermanentMagnetDCMotorExample')
sim('PermanentMagnetDCMotor');

Get the timestamp associated with the simulation log:

 simscape.logging.timestamp(simlog_PermanentMagnetDCMotor)
ans =

  int64

   530635937

Now, get the timestamp associated with the model:

 get_param(bdroot, 'RTWModifiedTimeStamp')
ans =

   530635937

The numbers are the same, which means that the simulation data is current.

When you modify a model, its timestamp changes. Open one of the blocks in the model and change a parameter value. Get the timestamp associated with the model:

 get_param(bdroot, 'RTWModifiedTimeStamp')
ans =

   530640461

Compare this number with the simulation log timestamp:

 simscape.logging.timestamp(simlog_PermanentMagnetDCMotor)
ans =

  int64

   530635937

Now the numbers are different, which means that the simulation data is stale and needs to be regenerated.

The function returns the simlog timestamp as int64. To compare it programmatically with a model timestamp, convert the simlog timestamp to a double, for example:

modelName = 'PermanentMagnetDCMotor';
simlog = simlog_PermanentMagnetDCMotor;
ts = simscape.logging.timestamp(simlog);
    if get_param(modelName,'RTWModifiedTimeStamp') == double(ts)
        updateSimlog = false;
    else
        updateSimlog = true;
    end

Input Arguments

collapse all

Simulation log workspace variable that contains the logged model simulation data, or a node within that variable, specified as a Node object. You specify the name of the simulation log variable by using the Workspace variable name parameter in the Simscape pane of the Configuration Parameters dialog box.

Version History

Introduced in R2021a