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.
- Category:
- Picks
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.