How do I use plot command in GUI?

I have a small problem which kept me busy for two days already. In my project I want to display a signal from Simulink in realtime in a Matlab GUI using event listeners. Therefore, I created a GUI using GUIDE with one axes on it. To update the graph, I created a function, which receives the data from Simulink. So far, everything works fine. When I try to use plot(), the graph just doesn't show up. If I use stem() insted, it works. If I open a figure outside the GUI, plot() is working. Somehow, the GUI doesn't like the plot(). Anybody has an idea how to solve this?
%Data from Simulink to plot
sim_data1 = data1.InputPort(1).Data;
sim_data2 = data2.InputPort(1).Data;
%scroll the graph to show only recent data
n=50;
if sim_time <n
xlim([0, 1500]);
else
xlim([sim_time-50 sim_time+1450]);
end
%plot the graph
plot(sim_time,sim_data1); %<- not worikng
stem(sim_time,sim_data1); %<- working
hold on;
Thank you very much for your help!
Thomas

 Respuesta aceptada

Geoff Hayes
Geoff Hayes el 27 de Nov. de 2015
Thomas - since you are plotting individual points, try changing the line width to make the point appear larger
plot(sim_time,sim_data1,'LineWidth',5)
or plot a shape at the point (much like the stem call does)
plot(sim_time,sim_data1,'o')
Do either of the above increase the visibility of the data points?

1 comentario

Thomas
Thomas el 1 de Dic. de 2015
Thank you for your reply. Both solutions didn't work. I've found another way by adding
global ph1;
ph1 = line([0],[0],'LineWidth',2,'Color','b');
to the GUI OpeningFcn function and adding this
global ph1;
xData1 = get(ph1,'XData');
yData1 = get(ph1,'YData');
xData1 = [xData1 sim_time];
yData1 = [yData1 sim_data1];
set(ph1,'XData',xData1,'YData',yData1);
drawnow;
to the update function. Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 26 de Nov. de 2015

Comentada:

el 1 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by