Main Content

simscape.logging.timestamp

Determine whether simulation log is current or stale

Description

example

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.

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_ssc_dcmotor (as specified by the Workspace variable name model configuration parameter) in your current workspace:

ssc_dcmotor
sim('ssc_dcmotor');

Get the timestamp associated with the simulation log:

 simscape.logging.timestamp(simlog_ssc_dcmotor)
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_ssc_dcmotor)
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 = 'ssc_dcmotor';
simlog = simlog_ssc_dcmotor;
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.

Introduced in R2021a