How to show a figure in the MATLAB App designer with both X and Y axis from signal in simulink real-time model?
Show older comments
How can we customize the x-axis of the instrumented axes in MATLAB App (with model running on Speedgoat)? I wanted to plot Speed vs Torque (signals from Simulink model) (in the axes) instead of separately plotting them with respect to time.
Answers (1)
Tejas
on 17 Sep 2024
Hello Devesh,
Start by adding an 'Axes Component' in App Designer. Below this component, place a button and assign a 'ButtonPushed' callback to it. Within this callback, follow these steps:
- Create a target object using 'slrealtime' to fetch real-time data from Speedgoat. Refer to this documentation for more details on 'slrealtime': https://www.mathworks.com/help/releases/R2022b/slrealtime/api/slrealtime.target.slrealtime.html
target_object = slrealtime('TargetPC1');
- Fetch real-time speed and torque data using 'getsignal'. More information about this function can be found in the documentation: https://www.mathworks.com/help/releases/R2022b/slrealtime/api/slrealtime.target.getsignal.html
speedData = getsignal(target_object, 'blockPath', portIndex);
torqueData = getsignal(target_object, 'blockPath', portIndex);
- Use the 'plot’ function to display the speed and torque data.
plot(app.UIAxes, speedData, torqueData);
With this setup, each time the button is clicked, real-time speed and torque data will be fetched and plotted in App Designer.
Categories
Find more on Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!