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 Commenti

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 il 1 Apr 2015
Modificato: SAGAR V il 1 Apr 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 il 1 Apr 2015
Modificato: per isakson il 1 Apr 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"

Accedi per commentare.

Risposte (1)

Arash Asgarinejad
Arash Asgarinejad il 4 Ago 2016
Modificato: Arash Asgarinejad il 4 Ago 2016
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 Commento

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.

Accedi per commentare.

Categorie

Scopri di più su MATLAB Support Package for Arduino Hardware in Centro assistenza e File Exchange

Richiesto:

il 30 Mar 2015

Community Treasure Hunt

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

Start Hunting!

Translated by