Why do I receive a "Error using Stateflow.?Clipboard/?copy" when I try to update Stateflow library interfaces that contain graphical Stateflow functions that are set to "subchart" in R2017a+? I am running a MATLAB script to update Stateflow library interfaces on a library that contains a graphical function set to be a "subchart". In this script, I create a "sfclipboard" object, grab the content from the current library, copy the content to the clipboard, and paste this to the new system that gets created by the script. When I run the script on my library that contains a graphical function set to be a "subchart", I receive the following error message: Error using Stateflow.Clipboard/copy All objects must have the same subviewer Error in update_library (line 168) Clipboard.copy(AllObjects); This seems like strange behavior since the subchart should be able to be copied without running into any issues through the clipboard object.
Kshitij Singh answered .
2025-11-20
% Find the matching chart. Get contents.
State = OldChart(iOldChart).find('-isa', 'Stateflow.State', '-depth', 1);
Transition = OldChart(iOldChart).find('-isa', 'Stateflow.Transition', '-depth', 1 );
Junction = OldChart(iOldChart).find('-isa', 'Stateflow.Junction', '-depth', 1);
Note = OldChart(iOldChart).find('-isa', 'Stateflow.Note', '-depth', 1);
Function = OldChart(iOldChart).find('-isa', 'Stateflow.Function', '-depth', 1);
Box = OldChart(iOldChart).find('-isa', 'Stateflow.Box', '-depth', 1);
% Find all objects
states = OldChart(iOldChart).find('-isa', 'Stateflow.State');
% Select the objects that are in the same subviewer
states = states(arrayfun(@(x)(x.Subviewer.Id == x.Chart.Id), states));