Main Content

Log String Data to the Simulation Data Inspector

This example shows how to build a Stateflow® chart that, based on numeric input data, concatenates string data into natural language output text. You can view the output text in the Simulation Data Inspector and the MATLAB® workspace. For more information about string data, see Manage Textual Information by Using Strings.

The model in this example uses Sine Wave blocks to provide the latitude and longitude of a point moving along a closed path. The Sine Wave blocks have an amplitude of 50, a bias of 0, and a frequency of 1. The Latitude block has a phase of 0, while the Longitude block has a phase of $\pi/2$.

The chart examines these coordinates and assigns the strings q1 and q2 according to these rules:

  • If latitude and longitude are positive, q1 = "North" and q2 = "east".

  • If latitude is positive and longitude is negative, q1 = "North" and q2 = "west".

  • If latitude is negative and longitude is positive, q1 = "South" and q2 = "east".

  • If longitude and longitude are negative, q1 = "South" and q2 = "west".

Then, the chart concatenates these strings into an output string sout.

View Simulation Results

During simulation, the model logs the signals coming into and out of the chart.

To examine the results of the simulation, open the Simulation Data Inspector and select the check boxes for the latitude, longitude, and sout signals. The latitude and longitude signals appear as sinusoidal curves. The sout signal appears as a transition plot. The transition plot displays the value of the string inside a band in which criss-crossed lines mark the changes in value.

To access the logged data in the MATLAB workspace, call the signal logging object logsout. Stateflow exports the string data sout as a MATLAB string scalar. For example, at the command prompt, enter:

Table = table(logsout.get("latitude").Values.Data, ...
    logsout.get("longitude").Values.Data, ...
Table.Properties.VariableNames = ...
ans =

  4x3 table

    Latitude    Longitude              QuadrantInfo          
    ________    _________    ________________________________

     28.232       41.267     "Location in Northeast Quadrant"
     40.425      -29.425     "Location in Northwest Quadrant"
    -30.593      -39.548     "Location in Southwest Quadrant"
    -38.638       31.735     "Location in Southeast Quadrant"

For more information on logging chart data, see Log Simulation Output for States and Data.

See Also

| (Simulink) |

Related Topics