How to plot real time values in matlab guide
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 30 Mär. 2015
Is there some problem with it? If it's not plotting until the loop is finished, put a "drawnow" command inside the loop.
per isakson
am 1 Apr. 2015
Bearbeitet: per isakson
am 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"
Antworten (1)
Arash Asgarinejad
am 4 Aug. 2016
Bearbeitet: Arash Asgarinejad
am 4 Aug. 2016
0 Stimmen
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 Kommentar
Walter Roberson
am 4 Aug. 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.
Kategorien
Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!