MATLAB: Do I receive an error message when using an output argument with the pasteTo method in Stateflow 7.3 (R2009a)

stateflow

In the help documentation under Stateflow > Using the API > Copying Objects > Copying Objects Individually, the example shows that the pasteTo method does take an output argument. However, when I use the same syntax, I receive the error message shown below:
??? One or more output arguments not assigned during call to "pasteTo".
The code works fine if the pasteTo method is used without an output argument. However, I require the handle to the pasted object and for that reason I am using the syntax which takes an output argument. A sample code is provided below:
% Create new model with a Stateflow Chart
sfnew('trial2')
rt = sfroot;
m = rt.find('-isa', 'Simulink.BlockDiagram', '-and', 'Name','trial2');
chart = m.find('-isa','Stateflow.Chart');
chart.view
% Add a State to the chart
sA = Stateflow.State(chart);
sA.Name = 'A';
sA.Position = [50 50 310 200];
% Save the model
sfsave(m.Name, 'trial2')
% Add another chart to the model
load_system('sflib')
b = add_block('sflib/Chart', 'trial2/Chart2');
pos = get(b,'Position');
pos(1) = pos(1) + 100; pos(3) = pos(3) + 100;
set(b,'Position',pos)
chart2 = m.find('-isa','Stateflow.Chart','Name','Chart2');
cb = sfclipboard;
cb.copy(sA);
% Paste the State, A, to the new Chart
% cb.pasteTo(chart2) % This Works
stateChart2 = cb.pasteTo(chart2); % This generates the error

Best Answer

This change has been incorporated into the documentation in Release 2009b (R2009b). For previous releases, read below for any additional information:
This is an error within the documentation for Stateflow within the "Using the API > Copying Objects > Copying Objects Individually" section. The pasteTo function does not take an output argument.
To get access to the handle to the pasted object, one can use the following example:
cb = sfclipboard;
cb.copy(sA); % where sA is a State and sA.Name = 'A';
cb.pasteTo(chart2)
newlypastedobjs = chart2.find('-isa','Stateflow.State','Name','A');
A simpler and cleaner way would be using the following code:
then = find(chart2);
cb = sfclipboard;
cb.pasteTo(chart2);
now = find(chart2);
newlypastedobjs = setdiff(now, then);