Azzera filtri
Azzera filtri

Real time plot simulink

35 visualizzazioni (ultimi 30 giorni)
ANGELO MASSARA
ANGELO MASSARA il 9 Lug 2024 alle 14:42
Risposto: Sahas il 16 Lug 2024 alle 11:31
Hi guys, i'm trying to do a polar plot with a matlab function in simulink that sould be tracked in real time during the simulation, but it doesn't work. Do you have any suggestions?

Risposte (1)

Sahas
Sahas il 16 Lug 2024 alle 11:31
As per my understanding, you want guidance to plot a “polarplot” function that can be tracked in real-time using a “MATLAB function block” inside Simulink. One possible solution is to use the “polarplot” function in MATLAB.
I have provided an example file “sample_polarplot_realtime_final.slx.” Execute this file and see plotting of the “polar axes” in real time.
Please refer to the following description for further understanding of the attached Simulink file:
The Simulink Model has two input blocks. “theta” is input for angle values and “rho” for the radius. I have provided such inputs to plot a circle.
The “updatePolarPlot” MATLAB Function Block contains the logic behind plotting the figure in real time.
function updatePolarPlot(theta, rho)
%persistent figure and axes to maintain the plot between function calls
persistent h ax;
% Check if the figure and axes are empty and initialize them if they are
if isempty(h) || isempty(ax)
h = figure;
ax = polaraxes(h);
end
n = numel(theta); %Getting thenumber of elements in theta or rho
for i = 1:n
% Update the polar plot with the current subset of theta and rho
% values iteratively
polarplot(ax, theta(1:i), rho(1:i));
title('Real-Time Polar Plot');
% Update the plot immediately
drawnow;
end
end
After executing, you will be able to see the figure plotting a complete circle in real time.
For further readings about the various functions and tools I have used, refer to the links below:
Plot line in polar coordinates - MATLAB polarplot - MathWorks India – Basics of the “polarplot” function in MATLAB.
I hope this helps you get started!

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by