plotting data on a refresh rate

I am working on a project where I am plotting received data from a port continously, at the moment I am able to do that but the data each time is plotted on a separate figure I want the data to be plotted on one figure on which this figure is refreshed at everytime the data is plotted.

Risposte (1)

Adam Danz
Adam Danz il 23 Dic 2019

0 voti

Somewhere in your code a figure is being generated explicitly, perhaps with the figure() command. That needs to be removed. To add data to an existing plot, it's best to include the axis handle in the plotting function inputs. You'll also need to issue the hold on command.
That's about as specific as I can get without seeing the plotting code.

4 Commenti

ahmed abdelmgeed
ahmed abdelmgeed il 23 Dic 2019
Modificato: Adam Danz il 23 Dic 2019
here is the code where I am plotting data, Note: the code is inside a loop
% Retrieve data and convert to milliVolts
bufferChA = adc2mv(pAppBufferChA.Value, chARangeMv, maxADCValue);
bufferChB = adc2mv(pAppBufferChB.Value, chBRangeMv, maxADCValue);
% Plot data
finalFigure = figure('Name','PicoScope 2000 Series Example - Fast Streaming Mode Capture', ... 'NumberTitle','off');
finalFigureAxes = axes('Parent', finalFigure);
hold(finalFigureAxes, 'on');
%Find the maximum voltage range and add 500mV.
maxYRange = max(chARangeMv, chBRangeMv) + 500;
ylim(finalFigureAxes, [(-1 * maxYRange) maxYRange]);
% Calculate time axis in milliseconds, then plot data.
timeLabel = 'Time (ms)';
time = (0:1:(length(bufferChA)) - 1) * double(samplingIntervalMs) * double(numSamplesPerAggregate);
plot(time, bufferChA, time, bufferChB);
title(finalFigureAxes, 'Fast Streaming Data Acquisition (Final)');
xlabel(timeLabel);
ylabel('Voltage (mv)');
grid(finalFigureAxes, 'on');
legend(finalFigureAxes, 'Channel A', 'Channel B');
hold(finalFigureAxes, 'off');
Adam Danz
Adam Danz il 23 Dic 2019
Modificato: Adam Danz il 24 Dic 2019
Yep, my intuition was correct. Your 3rd line of code is telling matlab to produce a figure on each iteration.
Instead, prior to your loop you can produce the figure.
% Produce the figure prior to the loop
finalFigure = figure(. . .);
finalFigureAxes = axes(finalFigure);
hold(finalFigureAxes, 'on');
% Update the axes
for i = 1:x
. . .
plot(finalFigureAxes, . . .)
. . .
end
I tried that but it only produces the figure with refreshing it but nothing is plot on the figure
finalFigure = figure('Name','PicoScope 2000 Series Example - Fast Streaming Mode Capture', ...
'NumberTitle','off');
finalFigureAxes = axes('Parent', finalFigure);
hold(finalFigureAxes, 'on');
i = 0
while (i>0)
% ploting second figure
% Process data if required - here the data will be plotted again.
disp('Processing data for plot...')
maxADCValue = get(ps2000DeviceObj, 'maxADCValue');
% Retrieve data and convert to milliVolts
bufferChA = adc2mv(pAppBufferChA.Value, chARangeMv, maxADCValue);
bufferChB = adc2mv(pAppBufferChB.Value, chBRangeMv, maxADCValue);
% Plot data
% Find the maximum voltage range and add 500mV.
maxYRange = max(chARangeMv, chBRangeMv) + 500;
ylim(finalFigureAxes, [(-1 * maxYRange) maxYRange]);
% Calculate time axis in milliseconds, then plot data.
timeLabel = 'Time (ms)';
time = (0:1:(length(bufferChA)) - 1) * double(samplingIntervalMs) * double(numSamplesPerAggregate);
plot(time, bufferChA, time, bufferChB);
ylim([(-1 * maxYRange) maxYRange])
title(finalFigureAxes, 'Fast Streaming Data Acquisition (Final)');
xlabel(timeLabel);
ylabel('Voltage (mv)');
grid(finalFigureAxes, 'on');
legend(finalFigureAxes, 'Channel A', 'Channel B');
hold(finalFigureAxes, 'off');
end
Adam Danz
Adam Danz il 26 Dic 2019
In order to diagnose the problem I'd need to run the code.
Since I don't have all of the information necessary to run the code, my first guess would be that the y-axis limit isn't being set correctly.
Comment-out (or remove) the two lines in your code that are setting the ylim() to test that.
Have you looked at the values of bufferChA, bufferChB, time?

Accedi per commentare.

Richiesto:

il 23 Dic 2019

Commentato:

il 26 Dic 2019

Community Treasure Hunt

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

Start Hunting!

Translated by