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

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 2015년 4월 1일
편집: SAGAR V 2015년 4월 1일
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 2015년 4월 1일
편집: per isakson 2015년 4월 1일
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"

댓글을 달려면 로그인하십시오.

답변 (1개)

Arash Asgarinejad
Arash Asgarinejad 2016년 8월 4일
편집: Arash Asgarinejad 2016년 8월 4일

0 개 추천

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

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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

질문:

2015년 3월 30일

댓글:

2016년 8월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by