MATLAB: AnalysisPoint fails when using multiple connect commands

analysispointconnectControl System Toolbox

I am attempting to connect multiple control subsystems (G1, G2) using the connect command. Each subsystem has analysis points connected to internal signals. I get an error when I connect the subsystems and attempt to keep the analysis points. The issue seems to be related to using multiple instances of the connect command. My current workaround is to use the connect command once. However, for building up large systems with multiple transfer functions this seems unwieldy.
Example code showing the problem is given below. I want to have access to analysis points "InnerError" and "OuterError" in the full model.
G1 = tf([1],[1 0]);
G1.u = 'OuterError';
G1.y = 'InnerCmd';
G2 = tf([1], [1 1]);
G2.u = 'InnerError';
G2.y = 'ActuatorCmd';
SumOuter = sumblk('OuterError = OuterCmd - Outer');
SumInner = sumblk('InnerError = InnerCmd - Inner');
disp('Connect everything at once. This works.')
Sys1 = connect(G1,G2,SumOuter,SumInner,{'OuterCmd','Outer','Inner'},'ActuatorCmd', {'InnerError','OuterError'})
disp('Connect things in series. This does not work with AnalysisPoints.')
P1 = connect(G1,SumOuter,{'OuterCmd','Outer'},'InnerCmd','OuterError');
P2 = connect(G2,SumInner,{'InnerCmd','Inner'},'ActuatorCmd','InnerError');
Sys2 = connect(P1,P2,{'OuterCmd','Outer','Inner'},'ActuatorCmd', {'InnerError','OuterError'});

Best Answer

This is actually a limitation of the "connect" function. I have notified the developers of this.
For now, the error points to the "AnalysisPoints_" block in P1 and P2. A workaround could be to rename this internally-created block within P1 and P2, like so:
P1 = connect(G1,SumOuter,{'OuterCmd','Outer'},'InnerCmd','OuterError');
P1.Blocks.AnalysisPoints_.Name = 'OuterError';
P2 = connect(G2,SumInner,{'InnerCmd','Inner'},'ActuatorCmd','InnerError');
P2.Blocks.AnalysisPoints_.Name = 'InnerError';
Sys2 = connect(P1,P2,{'OuterCmd','Outer','Inner'},'ActuatorCmd')
Renaming the analysispoints of each genss object will prevent the error, and should give the desired result.