Discussion:
simulink: add a legend in scope block
(too old to reply)
pietro
2011-01-27 14:00:05 UTC
Permalink
Hi guys,

how can I add a legend in a scope block?

thanks

Pietro
Phil Goddard
2011-01-28 04:35:05 UTC
Permalink
There is no in-built method for putting a legend on a scope.

However, since a scope is just a MATLAB figure window in disguise you can with a little bit of careful effort use standard Handle Graphics, along the lines of

% get handles to all scopes (the scope must have been opened at least once for this to work)
hScopes = findall(0,'Tag','SIMULINK_SIMSCOPE_FIGURE');
% Assume we want to put a legend on the first scope
% Get the axes on the scope
hAxes = findall(h(1),'Type','axes');
% Assume we want to put a legend on the first axis on the scope, and that
% it has 3 signals on it.
legend(hAxes(1),{'signal1','signal2','signal3'},'Color',[1 1 1]);
Note that the legend will not update or do anything else automatically if you change the signals going into the scope.

Phil.
Tannistha
2011-03-16 13:10:07 UTC
Permalink
Hi Phil thanks for the info. I have multiple scopes in a multilayer model. some scopes show different values for example the three phase currents and the resultant space vector in one scope. i would like to add legends at the top or side, saying, yellow phase1, purple phase 2,blue phase 3 etc, is there any way to do that?
Clemens
2012-10-19 08:26:08 UTC
Permalink
Post by Tannistha
Hi Phil thanks for the info. I have multiple scopes in a multilayer model. some scopes show different values for example the three phase currents and the resultant space vector in one scope. i would like to add legends at the top or side, saying, yellow phase1, purple phase 2,blue phase 3 etc, is there any way to do that?
Had the same problem yesterday (with 2011b) and found this solution using simplot:
http://blogs.mathworks.com/seth/2010/06/22/how-to-customize-the-simulink-scope/

Since 2012a there will be an additional option in the scope parameters:
http://blogs.mathworks.com/seth/2012/03/12/legends-for-simulink-scopes/

BR,
C ;-)

Loading...