Main Content

Create a Block Data Set and Edit Metadata

This example shows how to create a block data set from a Simscape block and edit the metadata.

Define Parameters for a Capacitor Block

Create a model with a Capacitor block.

capacitorReferenceBlock = "fl_lib/Electrical/Electrical Elements/Capacitor";
modelName = "example_model";
close_system(modelName,0) 
blockPath = modelName + "/Example Block";
new_system(modelName)
open_system(modelName)
add_block(capacitorReferenceBlock,blockPath);

Define parameters for the block.

set_param(blockPath,"c","2e-6")     % F
set_param(blockPath,"r","2e-6")     % Ohm

Create a Block Data Set from the Block

Use the partrepo.simscape.dataSetFromBlock function to create the block data set.

dataSet = partrepo.simscape.dataSetFromBlock(blockPath)
dataSet = 
  BlockDataSet with properties:

            ID: "||" (format)
      Metadata: [1×1 Metadata] (11 entries, Incomplete)
    Parameters: [1×1 Parameters] (3 entries)

Inspect the data set parameters and verify that they match the parameter settings for the block.

disp(dataSet.Parameters)
  Parameters with properties:

    c: 2e-6 (F)     | 
    g: 0 (1/Ohm)    | 
    r: 2e-6 (Ohm)   | 

Review the default metadata.

disp(dataSet.Metadata)
  Metadata (Incomplete) with properties:

            Manufacturer: ""
              PartNumber: ""
               BlockType: "SimscapeBlock"
    ParameterizationDate: "14-Jul-2025"
         SimulinkRelease: "25.1"
          ReferenceBlock: "fl_lib/Electrical/Electrical Elements/Capacitor"
          LibraryVersion: "25001000.1"
        ModelingEntityId: "foundation.electrical.elements.capacitor"
      ModelingEntityType: "SimscapeComponent"
        CustomIdentifier: ""
            PartSchemaId: "defaultSimscapeSchema"

All blocks use functional metadata fields such as ReferenceBlock and ModelingEntityId. The data set fails validation when this metadata is unavailable.

Set the Metadata

To create an ID entry and export a block data set to JSON, Simscape needs the Manufacturer and PartNumber metadata entries. Add these metadata entries to the block data set.

dataSet.Metadata.Manufacturer = "MyManufacturer";
dataSet.Metadata.PartNumber = "CC-0001";

Review the data set. Note that the ID field has a new value.

dataSet
dataSet = 
  BlockDataSet with properties:

            ID: "MyManufacturer|CC-0001|" (format)
      Metadata: [1×1 Metadata] (11 entries)
    Parameters: [1×1 Parameters] (3 entries)

Add a metadata entry to improve searchability.

dataSet.Metadata.RatedCapacitance = simscape.Value(2.5e-6,"F");

Review the revised metadata.

disp(dataSet.Metadata)
  Metadata with properties:

            Manufacturer: "MyManufacturer"
              PartNumber: "CC-0001"
               BlockType: "SimscapeBlock"
    ParameterizationDate: "14-Jul-2025"
         SimulinkRelease: "25.1"
          ReferenceBlock: "fl_lib/Electrical/Electrical Elements/Capacitor"
          LibraryVersion: "25001000.1"
        ModelingEntityId: "foundation.electrical.elements.capacitor"
      ModelingEntityType: "SimscapeComponent"
        CustomIdentifier: ""
            PartSchemaId: "defaultSimscapeSchema"

        RatedCapacitance: 2.5000e-06 (F)

Update the parameter origin information for the block data set.

dataSet.Parameters.c.Origin = "Estimated";
dataSet.Parameters.r.Origin = "From data sheet";

Review the updated parameter information for the block data set.

disp(dataSet.Parameters)
  Parameters with properties:

    c: 2e-6 (F)     | Estimated
    g: 0 (1/Ohm)    | 
    r: 2e-6 (Ohm)   | From data sheet

Export the data set to JSON

Use the validate function to validate the metadata.

validate(dataSet)

Now you can export the data set to JSON using the partrepo.exportDataSetsToJSON function. You can use the part number as the file name. Verify the JSON data once the export process completes.

partrepo.exportDataSetsToJSON(dataSet,dataSet.Metadata.PartNumber)
jsonData = fileread('CC-0001.json');
disp(jsonData)
{
  "Metadata": [
    {
      "Name": "Manufacturer",
      "Value": "MyManufacturer"
    },
    {
      "Name": "PartNumber",
      "Value": "CC-0001"
    },
    {
      "Name": "BlockType",
      "Value": "SimscapeBlock"
    },
    {
      "Name": "ParameterizationDate",
      "Value": "14-Jul-2025"
    },
    {
      "Name": "SimulinkRelease",
      "Value": "25.1"
    },
    {
      "Name": "ReferenceBlock",
      "Value": "fl_lib/Electrical/Electrical Elements/Capacitor"
    },
    {
      "Name": "LibraryVersion",
      "Value": "25001000.1"
    },
    {
      "Name": "ModelingEntityId",
      "Value": "foundation.electrical.elements.capacitor"
    },
    {
      "Name": "ModelingEntityType",
      "Value": "SimscapeComponent"
    },
    {
      "Name": "CustomIdentifier",
      "Value": ""
    },
    {
      "Name": "PartSchemaId",
      "Value": "defaultSimscapeSchema"
    },
    {
      "Name": "RatedCapacitance",
      "Value": 2.5e-06,
      "Unit": "F"
    }
  ],
  "Parameters": [
    {
      "Name": "c",
      "ValueExpr": "2e-6",
      "Unit": "F",
      "Origin": "Estimated"
    },
    {
      "Name": "g",
      "ValueExpr": "0",
      "Unit": "1/Ohm",
      "Origin": ""
    },
    {
      "Name": "r",
      "ValueExpr": "2e-6",
      "Unit": "Ohm",
      "Origin": "From data sheet"
    }
  ]
}

See Also

| |

Topics