Main Content

saveChanges

Save data in memory for connected data source to disk

Since R2024a

    Description

    example

    saveChanges(connectionObj) returns 1 (true) if the data connection successfully saves data in memory to the disk, and 0 (false) otherwise.

    The behavior of the saveChanges function depends on the connected data source:

    • Base workspace — The function returns an error.

    • Model workspace

      • Data source is the model file — The function saves the model.

      • Data source is a MAT-file or .m file — The function saves the data to the file.

      • Data source is MATLAB® code — The function returns an error.

    • Data dictionary — The function saves the data dictionary and referenced dictionaries.

    Examples

    collapse all

    Update the value of a variable in the model workspace. Then save the change.

    mw = Simulink.data.connect("myModel.slx")
    mw.x = mw.x + 2;
    success = saveChanges(mw)
    
    success = 
    
    logical
        1
    

    Check whether the model workspace contains unsaved changes.

    dirty = hasUnsavedChanges(mw)
    
    dirty = 
    
    logical
        0
    

    Input Arguments

    collapse all

    Connection to data source, specified as a Simulink.data.DataConnection object.

    Version History

    Introduced in R2024a