Simple, but stumped. Using 'xline' to create animated "play marker" across waveform plot.
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Peter Beringer
il 25 Nov 2020
Commentato: Peter Beringer
il 30 Nov 2020
I am trying to create a plot of a waveform that has a "play marker"/vertical line running across. Have been trying with 'xline' drawing at position 'ii' in a for loop, but I can't figure out how to clear previous lines, so every line position stays on the plot. (Have included test data lines at the top so it can run.)
I know the solution is bound to be really simple, but it eludes me. Currently investigating whether the 'animatedline' function call is better suited.
Many thanks for any help.
Cheers.
Fs = 48000;
Position01 = rand(Fs,11);
StartIndex = 1;
FinishIndex = 100;
figure;
subplot(2,1,1);
plot(Position01(StartIndex:FinishIndex,11));
hold on
title('test');
xlabel('test');
ylabel('test');
subplot(2,1,2);
plot(Position01(StartIndex:FinishIndex,1));
title('test');
xlabel('test');
ylabel('test');
for ii = 1 : length(Position01(StartIndex:FinishIndex,11))
xline(ii);
drawnow
end
0 Commenti
Risposta accettata
Alan Moses
il 28 Nov 2020
You may use the following lines of code to clear the previous line:
children = get(gca, 'children');
delete(children(1));
The above lines of code can be added to your script as follows:
for ii = 1 : length(Position01(StartIndex:FinishIndex,11))
%Ensures the original plot stays and clears only the vertical lines plotted
if(ii >= 2)
children = get(gca, 'children');
delete(children(1));
end
xline(ii);
drawnow
end
Hope this helps!
Più risposte (1)
Steven Lord
il 30 Nov 2020
Rather than deleting and recreating the line, change its properties.
% Define the data
x = 0:360;
y = sind(x);
% Create three plots
plot(x, y); % Main sine curve
hold on
h = xline(x(1)); % vertical cursor
m = plot(x(1), y(1), 'ro'); % intersection circle
% Update the h and m lines
for whichX = 1:10:numel(x)
h.Value = x(whichX);
m.XData = x(whichX);
m.YData = y(whichX);
pause(0.25)
end
Vedere anche
Categorie
Scopri di più su Animation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!