Main Content

partrepo.importDataSetsFromJSON

Import block data sets from a JSON file

Since R2025a

    Description

    PartDataSets = partrepo.simscape.importDataSetsFromJSON(FileNames) returns a cell array of BlockDataSet objects imported from the files, FileNames.

    example

    Examples

    collapse all

    This example shows how to create a block data set, store it in a JSON file, and then import the data set from the JSON file.

    Create a model that contains a Simscape block. This example uses a Capacitor block from the Foundation Library.

    modelName = "myModel";
    close_system(modelName,0) 
    libraryBlockName = "fl_lib/Electrical/Electrical Elements/Capacitor";
    open_system(new_system(modelName));
    blockName = add_block(libraryBlockName,modelName + "/" + "Example block");
    

    Create a block data set from the Capacitor block.

    myDataSet = partrepo.simscape.dataSetFromBlock(blockName)
    myDataSet = 
    
      BlockDataSet with properties:
    
                ID: "||" (format)
          Metadata: [1×1 Metadata] (11 entries, Incomplete)
        Parameters: [1×1 Parameters] (3 entries)
    

    In the Metadata property of the BlockDataSet object, add values for the Manufacturer and PartNumber properties.

    myDataset.Metadata.Manufacturer = "My Manufacturer";
    myDataset.Metadata.PartNumber = "U312_45";

    Export the block data set to a JSON file. Use the part number as the file name.

    partrepo.exportDataSetsToJSON(myDataset,myDataset.Metadata.PartNumber)

    Import the block data set from the JSON file and display the data.

    results = partrepo.importDataSetsFromJSON('U312_45.json');
    disp(results{1})
    myDataSet = 
    
      BlockDataSet with properties:
    
                ID: "My Manufacturer|U312_45|" (format)
          Metadata: [1×1 Metadata] (11 entries)
        Parameters: [1×1 Parameters] (3 entries)
    

    Input Arguments

    collapse all

    Location of the stored block data sets, specified as a string scalar or character vector that indicates the location of JSON files.

    Data Types: double | char | string

    Output Arguments

    collapse all

    Simscape part data sets, returned as a cell array of partrepo.simscape.BlockDataSet objects.

    Version History

    Introduced in R2025a