How to plot real time values in matlab guide

I have data coming from arduino through serial port and I need to plot these values in matlab guide having axes and pushbutton. How can i do this??
the following code gives the real time plot in matlab....
how to modify the code in order that i can use it in pushbutton function in matlab guide.
thnx and regards sagarvs
serialPort = 'COM8';
serialObject = serial(serialPort);
fopen(serialObject);
fprintf(serialObject,'SYSTEM:REMOTE');
time = now;
pressure = 0;
figureHandle = figure('NumberTitle','off',...
'Name','Pressure Characteristics',...
'Color',[0 0 0],'Visible','off');
axesHandle = axes('Parent',figureHandle,...
'YGrid','on',...
'YColor',[0.9725 0.9725 0.9725],...
'XGrid','on',...
'XColor',[0.9725 0.9725 0.9725],...
'Color',[0 0 0]);
hold on;
plotHandle = plot(axesHandle,time,pressure,'Marker','.','LineWidth',1 ...
,'Color',[0 1 0]);
xlim(axesHandle,[min(time) max(time+0.001)]);
xlabel('Time','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
ylabel('Pressure in bar','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
title('Pressure Characteristics','FontSize',15,'Color',[1 1 0]);
stopTime = '10/07 21:53';
timeInterval = 0.005;
count = 1;
while ~isequal(datestr(now,'mm/DD HH:MM'),stopTime)
time(count) = datenum(clock);
% To measure current the command is MEASURE:CURRENT:DC?
fprintf(serialObject,'MEASURE:PRESSURE:DC?');
pressure(count) = fscanf(serialObject,'%f'); %#ok<SAGROW>
set(plotHandle,'YData',pressure,'XData',time);
set(figureHandle,'Visible','on');
datetick('x','mm/DD HH:MM');
pause(timeInterval);
count = count +1;
end
fprintf(serialObject,'SYSTEM:LOCAL');
fclose(serialObject);
delete(serialObject);
clear serialObject;

3 comentarios

Image Analyst
Image Analyst el 30 de Mzo. de 2015
Is there some problem with it? If it's not plotting until the loop is finished, put a "drawnow" command inside the loop.
To learn how to format your code, so we can read it, read this.
SAGAR V
SAGAR V el 1 de Abr. de 2015
Editada: SAGAR V el 1 de Abr. de 2015
The code presented above works fine when i use it directly in editor window and run it.
But i want to use in push button function inside the code obtained by the guide GUI so that real time graph is obtained in the axes defined in the GUI.
Can you please help me to implement this one.
per isakson
per isakson el 1 de Abr. de 2015
Editada: per isakson el 1 de Abr. de 2015
One approach:
  • convert the code to a function (script is also possible)
  • call the the function interactively to make sure it works
  • call that function from your "push button function"

Iniciar sesión para comentar.

Respuestas (1)

Arash Asgarinejad
Arash Asgarinejad el 4 de Ag. de 2016
Editada: Arash Asgarinejad el 4 de Ag. de 2016

0 votos

I have the same question! Looks like we found our real-time plotting code from the same place, I have almost exactly the same code. I saved my code in a function, and when I call the function from my "push button function," it opens the real-time plot in a new window, instead of plotting it in my axes within the GUI. How can I make it so it plots in my GUI axes?

1 comentario

Walter Roberson
Walter Roberson el 4 de Ag. de 2016
Remove the assignment to figureHandle. Replace the assignment to axesHandle with one that assigns a copy of the existing axes that you want to draw into.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.

Preguntada:

el 30 de Mzo. de 2015

Comentada:

el 4 de Ag. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by