Can I specify custom legend labels when binding instruments to Axes in my SLRT app for Speedgoat?

4 vues (au cours des 30 derniers jours)
I have created an SLRT app using the Simulink Real-Time App Generator. I selected several signals from my model to be displayed in axes.
For a scalar signal, the app code uses 'connectLine' to bind an instrument to Axes with the following block-path syntax:
% Bind scalar signal with block-path syntax hInst.connectLine(app.myAxes, {'slrt_ex_osc/Signal Generator'}, 1);
However, in the legend of the axes, the signal label is not to my liking, as it shows the full block path:
Similarly, if I try to display several elements from a named bus signal 'MuxOut' in one axes, the following syntax is used:
% Bind bus signal elements hInst.connectLine(app.myAxes, 'MuxOut', 'BusElement', 'Sig1'); hInst.connectLine(app.myAxes, 'MuxOut', 'BusElement', 'Sig2');
For the bus element signals, the legend shows just the bus name which makes it impossible to tell the bus element signals from one bus apart:
Is there a way to have control over the legend labels used for each signal when using 'connectLine'? 

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 23 Mar 2025
Starting in R2024a, you can specify a "Line Label" for each signal that is mapped to Axes (see the release notes). The corresponding code is:
myLineStyle = slrealtime.instrument.LineStyle(); myLineStyle.Label = 'Custom Label'; hInst.connectLine(app.myAxes, {'myModel/myBlock'}, 1, ...     'LineStyle', myLineStyle);
In R2023b and prior, the ability to customize the legend labels when using instruments and SLRT App Generator is not available.
Workaround for scalar signals:
Make sure that you name the signals in your model for what you want them to appear in the legend. This way, the signal will appear in the dedicated "Named Signals" section in SLRT App Generator:
After selecting the signal from the "Named Signals" section and adding it to your app, the App Designer code for the SLRT connectLine() function will look like the following: 
hInst.connectLine(app.myAxes, {'MySignal'}); 
So instead of using connectLine() and passing by block path and port ID, the instrumented signal name is passed to connectLine() instead. This way, the legend will just show the name of the signal.
To use a different signal label for a signal that is already named, you can make a second dummy signal branched from it like below with a Signal Copy block:
Workaround for bus signals:
For bus signals, the workaround is to create lines of scalar signals for each signal that you want to observe, and add a signal label:
The corresponding code is:
hInst.connectLine(app.myAxes, {'MySig1', 'MySig2'});

Plus de réponses (0)

Catégories

En savoir plus sur Troubleshooting in Simulink Real-Time dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by