Sinusoid plots, XTick
Mostra commenti meno recenti
I've plotted a couple periods of y=5*sqrt(2)*cos(2*pi*t+pi/4) and I would like to use XTick (preferably, if it works) to set the labels on the x-axis to be all of the values of t such that y is at a maximum, minimum, or zero. I could do it manually, but I need it to be generic (i.e. I could change the function and the labels would conform to it). It could do it if there wasn't a phase shift, but there is. Does anyone know how to do this? Thanks.
For clarification: This image is the plot as it is now: http://img684.imageshack.us/img684/7678/whatihaveb.png I drew vertical lines where I want tick marks in this image: http://img838.imageshack.us/img838/1121/whatiwant.png
5 Commenti
Jan
il 17 Mar 2011
What exactly does "generic" mean here? What should be recognized automatically?
Patrick Star
il 17 Mar 2011
Walter Roberson
il 17 Mar 2011
When you change y, is the function still certain to be sinusoid? Finding all the zeros of an arbitrary "black box" function is impossible.
What is the highest frequency that needs to be dealt with?
Patrick Star
il 17 Mar 2011
Walter Roberson
il 18 Mar 2011
If you push the frequency high enough, the labels will overlap. Higher still and it will be a terrible mess to plot, when you start approaching one cycle per pixel.
Risposta accettata
Più risposte (1)
the cyclist
il 17 Mar 2011
This code will identify just the maximum (not the minimum or zeros), but you should be able to see how to generalize it.
A cautionary note: you'll see in the plot from my code that it does not identify the second occurrence of the true maximum of the sine wave. This is because when I have sampled at every 0.01 interval of x, it is not a maximum of y there. You may need to code around that in your own data.
x = 0:0.01:4*pi;
y = sin(x);
figure
plot(x,y)
set(gca,'YLim',[-2 2])
[ymax indexToYmax] = max(y);
xAtMaxY = x(indexToYmax);
set(gca,'XTick',xAtMaxY);
set(gca,'XTickLabel',num2str(xAtMaxY));
set(gca,'XGrid','On')
Categorie
Scopri di più su Annotations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
