Making a counter out of cycling data for a quasi-realtime plot

Consider the following dummy data from testing a battery:
%%Data
t = 1:1:100; t = t';
shape = [1 2 3 4 5 5 4 3 2 1]';
voltage = [shape; shape; shape; shape; shape; shape; shape; shape; shape; shape];
cycle = 10*ones(10,1);
intCycle = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10];
%%Quasi-realtime plot
% loop for time-dependent measurements
n = numel(time);
figure, xlim([min(time) max(time)]), ylim([-1.5 5]), xlabel('time (s)'), ylabel('voltage (V)');
hold on
% plot first point
h(1) = plot(time(1), voltage(1));
handles.slider = uicontrol('style', 'slider',...
'position', [350 10 200 20], ...
'min', 0, 'max', 60, ...
'sliderstep',[0.1 0.1], 'value', 10);
slidervalue = get(handles.slider, 'value');
refreshRate = 1/slidervalue;
% loop for cycle-dependent measurements
m = numel(cycle);
figure, xlim([0 numel(cycle)]), ylim([0 max(voltage)]), xlabel('Cycle #'), ylabel('voltage (V)');
hold on
% plot first point
h(2) = plot(intCycle(1), voltage(1));
set(h(4), 'color', 'magenta');
for i = 1:n-1
% time dependent
set(h(1), 'XData', time(1:i), 'YData', voltage(1:i));
drawnow;
pause(refreshRate);
slidervalue = get(handles.slider, 'value');
refreshRate = 1/slidervalue;
end
hold off
What I want to do is plot the voltage at the end of each cycle. Each cycle is 10 seconds long in this example, but the cycle length will most likely never be constant, so there needs to be a way (probably within the loop) to check if the time in cycle(i,1) is complete. Once one cycle is complete, I want one data point plotted on the axis in figure 2.
So, the way it should go in this example is that 10 points are plotted with respect to time in figure 1 for every 1 point plotted with respect to cycle in figure 2.

4 Comments

Me no follow... :)
if the time in cycle(i,1) is complete ... what is the operational definition of how to know the cycle is complete or not?
For this example, when the i loop reaches some multiple of 10. So when mod(i,10) = 0, then we can plot the cycling data. However, 10 is used in this example for convenience and I need something that can handle any value in each cell of cycle(i,1).
More rigorously, let's assume the first 2 values of the cycle array are this:
cycle(1) = 4
cycle(2) = 12
Then the code needs to plot a point at the end of cycle(1), which corresponds to time(4), and a point at cycle(2), which corresponds to time(16).
How did you get that again????
Are you simply looking for a way to determine your "signal" has crossed a threshold rising and falling to use as a flag for the second plot?

Answers (0)

This question is closed.

Tags

Asked:

on 6 Aug 2013

Closed:

on 26 Jun 2025

Community Treasure Hunt

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

Start Hunting!