How to manually move (smoothly) a set of evenly spaced xlines
Afficher commentaires plus anciens
In R2020a on a plot I plan on having a loop to produce 20 xlines that are 200 samples apart. (I know that in later versions, one xline can have an array, but not in R2020a.)
I would like to be able to manually move all of them by some offset < 200, preferably with a mouse. Ideally, I would select the left-most xline with a mouse (or even any point between the first two xlines), and as I move the mouse to the right, all 20 xlines would move smoothly to the right keeping their difference of 200 samples intact. When I let go of the mouse select key, then I would like to know the exact x-coordinate of the left-most xline. (Using the figure tooltip only gives an approximate x-coordinate.) I should then be able to repeat this until I am satisified that all the gaps between the xlines have captured the data symbols correctly.
In following example, I would want to slide the xlines to lie on top of the peaks. (Actual signals are not as clear.)
f = 50*1e6;
phi = 14*pi/9;
t = linspace(0,1,100e3);
y = sin(2*pi*f*t + phi);
plot(y)
for ii = 0:10
xline(ii*200 + 25);
end
xlim( [1 2300] );
Réponse acceptée
Plus de réponses (1)
With your clarifying picture there may be another possibility. You could just put the xline objects in their required position automatically.
x = 0:3600;
y = sind(x);
L = islocalmax(y);
plot(x, y, '-');
hold on
peakLocations = x(L);
for whichpeak = 1:numel(peakLocations)
xline(peakLocations(whichpeak));
end
Another potential approach to highlight the peaks is to add a stem plot.
% stem(x(L), y(L))
3 commentaires
Paul Hoffrichter
le 18 Nov 2022
Steven Lord
le 18 Nov 2022
Do you need to perform a visual sanity check or can you programmatically check that the true values returned from islocalmax (and potentially its opposite islocalmin if you're looking for both types of local extrema) are equally spaced?
Paul Hoffrichter
le 18 Nov 2022
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


