File Exchange Pick of the Week

February 24th, 2012

Interactive Curve Class

Jiro's pick this week is Interactive Curve Class by Maxim Vedenyov.

Have you ever wanted to create a test data set that you could use to test your program? I've used functions like rand and randn plenty of times, but sometimes I want to create a signal that looks a certain way or has particular characteristics.

The best way I could think of was to make use of data linking and/or data brushing. With data linking, you can plot a graph and have the graphed line linked to the original variable. Then you can change the values of the variable and the graph will automatically update. With data brushing, you can interactively select data points on a plot and change the values. But it requires right-clicking on a point, selecting a menu item, and typing in a new value. What I really wanted to do was to be able to click and drag, sort of like the Signal Builder block in Simulink that allows you to create arbitrary signals.

And now, I introduce you to "Interactive Curve Class" by Maxim! When I saw the title and the screenshot, I knew this was what I was looking for.

ic = interactive_curve;

Once you have created a curve, you can create vectors by interpolating:

x = 0:0.01:20;
y = ic.interpData(x, true); % 'true' indicates that the signal should be periodic
figure;
plot(x, y);

or you can even create a function that you can use to evaluate at any arbitrary point:

ic.generateMFile('mySignal.m', true);
   function yi = mySignal(xi)
   % autogenerated interpolation function 23-Feb-2012 19:38:50
   % by interactive_curve object

   xi = mod(xi-(0.0000000e+000),1.0000000e+001);
   x = [1.5000000e-001 1.4861751e+000 2.8225806e+000 3.9976959e+000 ...
       4.7811060e+000 6.2327189e+000 7.2695853e+000 8.0299539e+000 ...
       9.0000000e+000 1.0000000e+001];
   y = [-3.0701754e-003 -3.0701754e-003 -4.6359649e-001  6.1096491e-001 ...
       3.0394737e-001  4.9429825e-001  8.5657895e-001  2.7324561e-001 ...
       0.0000000e+000  0.0000000e+000];
   yi = interp1(x, y, xi, 'pchip');

Maxim has included several examples, a couple of which involve graphical user interfaces. He also has a YouTube video of it in action. Thanks for a very useful tool, Maxim!

Comments

Give it a try and let us know what you think here or leave a comment for Maxim.


Get the MATLAB code

Published with MATLAB® 7.13

One Response to “Interactive Curve Class”

  1. Faten replied on :

    Just Great, now i do not have an application for this, but some time i will. its very good to test data you know how it is look without actually writing its values

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.