Borrar filtros
Borrar filtros

HOw to set axis?

3 visualizaciones (últimos 30 días)
tim
tim el 15 de Mzo. de 2016
Hi to everyone, I found the following usefull code on this website, my problem is that I am not able to modify the axis. If I don't change the code at all, the axis limits follow the input values, so if i send some values between 0 and 5 i get thi axis limit, if I send values from 0 to 100 the axis limit change. I need to get fixed axis. For example from 0 to 130 on the y axis. About x axis,it is different. I need this graph to plot how the temperature changes as a function of the time. So each sample that I receive should be plotted in the right time windows, so maybe i need like a timer. Can someone help me on?? at leat with one of my problems?? thank you
function real_time_data_stream_plotting
This example demonstrates how to automatically read a set number of data bytes as and when they are available. This MATLAB® script also generates a real time plot of streaming data collected from the TCPIP server.
The script may be updated to use any instrument/device/TCPIP server to collect real time data. You may need to update the IP address and port.
To generate a report of this entire script, you may use the PUBLISH command at the MATLAB® command line as follows:
publish(real_time_data_plot);
% Author: Ankit Desai
% Copyright 2010 - The MathWorks, Inc.
%%Create the interface object
% Create a TCPIP object listening to port 19 (Character Generator).
%
% *Note* : To enable character generator service at port 19 on a Windows platform, enable:
%
% Control Panel > Add Remove Programs > Add/Remove Windows Component > Networking Services
%
interfaceObject = tcpip('localhost',19);
Setup a figure window and define a callback function for close operation
figureHandle = figure('NumberTitle','off',...
'Name','Live Data Stream Plot',...
'Color',[0 0 0],...
'CloseRequestFcn',{@localCloseFigure,interfaceObject});
Setup the axes
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]);
xlabel(axesHandle,'Number of Samples');
ylabel(axesHandle,'Value');
Initialize the plot and hold the settings on
hold on;
plotHandle = plot(axesHandle,0,'-y','LineWidth',1);
%%Setup interface object to read chunks of data
% Set the number of bytes to read at a time
bytesToRead = 500;
Define a callback function to be executed when desired number of bytes are available in the input buffer
interfaceObject.BytesAvailableFcn = {@localReadAndPlot,plotHandle,bytesToRead};
interfaceObject.BytesAvailableFcnMode = 'byte';
interfaceObject.BytesAvailableFcnCount = bytesToRead;
Open the interface object
fopen(interfaceObject);
pause(3);
snapnow;
%%Implement the bytes available callback
function localReadAndPlot(interfaceObject,~,figureHandle,bytesToRead)
Read the desired number of data bytes
data = fread(interfaceObject,bytesToRead);
Update the plot
set(figureHandle,'Ydata',data);
%%Implement the close figure callback
function localCloseFigure(figureHandle,~,interfaceObject)
Clean up the interface object
fclose(interfaceObject);
delete(interfaceObject);
clear interfaceObject;
Close the figure window
delete(figureHandle);

Respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by