I love the power and extensibility of MATLAB. Want to create a line you can drag across your plot? It’s not so hard to create
one. (In fact, our very own Doug recently posted a nice video showing how you might create a line that follows the motion of the cursor.) Want more than one draggable line? Perhaps with
data tips? Then want to be able to crop and export your plots based on where you drag those lines? Easily create your own
utility, OR simply download Scott Hirsch’s DUALCURSOR. DUALCURSOR is Brett’s Pick as this week’s featured function.
Scott elegantly wrote of his function: “A picture’s worth a thousand words.” In this case, though, a picture doesn’t do justice
to the words (code). Rather than try to show you via screen captures the utility of so interactive a function, I’m going to
encourage you to download Scott’s file and play around with it. You’ll see how easy it is to reposition the dual cursors,
and how the data tips update as you drag the lines. Then, with a right-click, you’ll see how you can easily extract (to the workspace or
to a new figure) the portion of your data enclosed by the cursors.
This creates variables Fs and y in your current workspace
Ns = 2^12; Y = fft(y,Ns); Y = 2/Ns*abs(Y(1:Ns/2)); df = Fs/Ns; f = (0:1:Ns/2-1)*df;
figure; plot(f,100*sqrt(Y)) title('My cursor example'); xlabel('Frequency (Hz)'); ylabel('Amplitude'); axis([0 1200 0 inf]);
dualcursor % Note: Make sure you try right-clicking and exporting sub-portions of your % plot. Also, try dragging the datatip labels (which show the dx and dy % values) around. Very nice!
Might as well give the data a listen:
player = audioplayer(y, Fs); play(player,[1 (get(player, 'SampleRate')*3)]);
Published with MATLAB® 7.6
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.