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