{"id":3348,"date":"2012-02-24T09:01:52","date_gmt":"2012-02-24T14:01:52","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=3348"},"modified":"2016-05-17T21:09:05","modified_gmt":"2016-05-18T01:09:05","slug":"interactive-curve-class","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2012\/02\/24\/interactive-curve-class\/","title":{"rendered":"Interactive Curve Class"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/35056-interactive-curve-class\">Interactive Curve Class<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/49003\">Maxim Vedenyov<\/a>.\r\n\r\nHave you ever wanted to create a test data set that you could use to test your program? I've used functions like <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/rand.html\"><tt>rand<\/tt><\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/randn.html\"><tt>randn<\/tt><\/a> plenty of times, but sometimes I want to create a signal that looks a certain way or has particular characteristics.\r\n\r\nThe 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\r\nvalues of the variable and the graph will automatically update. With data brushing, you can interactively select data points\r\non a plot and change the values. But it requires right-clicking on a point, selecting a menu item, and typing in a new value.\r\nWhat I really wanted to do was to be able to click and drag, sort of like the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/simulink\/slref\/signalbuilder.html\">Signal Builder<\/a> block in Simulink that allows you to create arbitrary signals.\r\n\r\nAnd now, I introduce you to \"Interactive Curve Class\" by Maxim! When I saw the title and the screenshot, I knew this was what\r\nI was looking for.\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">ic = interactive_curve;<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_interactivecurves\/InteractiveCurveAnimation.gif\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nOnce you have created a curve, you can create vectors by interpolating:\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">x = 0:0.01:20;\r\ny = ic.interpData(x, true); <span style=\"color: #228b22;\">% 'true' indicates that the signal should be periodic<\/span>\r\nfigure;\r\nplot(x, y);<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_interactivecurves\/potw_interactivecurves_plot.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nor you can even create a function that you can use to evaluate at any arbitrary point:\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">ic.generateMFile(<span style=\"color: #a020f0;\">'mySignal.m'<\/span>, true);<\/pre>\r\n<pre>   function yi = mySignal(xi)\r\n   % autogenerated interpolation function 23-Feb-2012 19:38:50\r\n   % by interactive_curve object\r\n\r\n<\/pre>\r\n<pre>   xi = mod(xi-(0.0000000e+000),1.0000000e+001);\r\n   x = [1.5000000e-001 1.4861751e+000 2.8225806e+000 3.9976959e+000 ...\r\n       4.7811060e+000 6.2327189e+000 7.2695853e+000 8.0299539e+000 ...\r\n       9.0000000e+000 1.0000000e+001];\r\n   y = [-3.0701754e-003 -3.0701754e-003 -4.6359649e-001  6.1096491e-001 ...\r\n       3.0394737e-001  4.9429825e-001  8.5657895e-001  2.7324561e-001 ...\r\n       0.0000000e+000  0.0000000e+000];\r\n   yi = interp1(x, y, xi, 'pchip');\r\n\r\n<\/pre>\r\nMaxim has included several examples, a couple of which involve graphical user interfaces. He also has a YouTube <a href=\"http:\/\/youtu.be\/cjej0nf0fcY\">video<\/a> of it in action. Thanks for a very useful tool, Maxim!\r\n\r\n<b>Comments<\/b>\r\n\r\nGive it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=3348#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/35056-interactive-curve-class#comments\">comment<\/a> for Maxim.\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_1f4bbcfbe76a476b8da347ddadf40f61() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='1f4bbcfbe76a476b8da347ddadf40f61 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 1f4bbcfbe76a476b8da347ddadf40f61';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2012 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\r\n\r\n\r\n\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae 7.13<\/p>\r\n\r\n<\/div>\r\n<!--\r\n1f4bbcfbe76a476b8da347ddadf40f61 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007 % Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/35056-interactive-curve-class Interactive % Curve Class> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/49003 Maxim % Vedenyov>.\r\n%\r\n% Have you ever wanted to create a test data set that you could use to\r\n% test your program? I've used functions like\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/rand.html |rand|> and\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/randn.html |randn|> plenty of\r\n% times, but sometimes I want to create a signal that looks a certain way\r\n% or has particular characteristics.\r\n%\r\n% The best way I could think of was to make use of\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/data_analysis\/_brh7_h0-1.html data % linking> and\/or\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/data_analysis\/_brh7_p3-1.html data % brushing>. With data linking, you can plot a graph and have the graphed\r\n% line linked to the original variable. Then you can change the values of\r\n% the variable and the graph will automatically update. With data\r\n% brushing, you can interactively select data points on a plot and change\r\n% the values. But it requires right-clicking on a point, selecting a menu\r\n% item, and typing in a new value. What I really wanted to do was to be\r\n% able to click and drag, sort of like the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/simulink\/slref\/signalbuilder.html % Signal Builder> block in Simulink that allows you to create arbitrary\r\n% signals.\r\n%\r\n% And now, I introduce you to \"Interactive Curve Class\" by Maxim! When I\r\n% saw the title and the screenshot, I knew this was what I was looking for.\r\n\r\nic = interactive_curve;\r\n\r\n%%\r\n% <<InteractiveCurveAnimation.gif>>\r\n%\r\n% Once you have created a curve, you can create vectors by interpolating:\r\n\r\nx = 0:0.01:20;\r\ny = ic.interpData(x, true); % 'true' indicates that the signal should be periodic\r\nfigure;\r\nplot(x, y);\r\n\r\n%%\r\n% <<potw_interactivecurves_plot.png>>\r\n%\r\n% or you can even create a function that you can use to evaluate at any\r\n% arbitrary point:\r\n\r\nic.generateMFile('mySignal.m', true);\r\n\r\n%%\r\n%     function yi = mySignal(xi)\r\n%     % autogenerated interpolation function 23-Feb-2012 19:38:50\r\n%     % by interactive_curve object\r\n%\r\n%     xi = mod(xi-(0.0000000e+000),1.0000000e+001);\r\n%     x = [1.5000000e-001 1.4861751e+000 2.8225806e+000 3.9976959e+000 ...\r\n%         4.7811060e+000 6.2327189e+000 7.2695853e+000 8.0299539e+000 ...\r\n%         9.0000000e+000 1.0000000e+001];\r\n%     y = [-3.0701754e-003 -3.0701754e-003 -4.6359649e-001  6.1096491e-001 ...\r\n%         3.0394737e-001  4.9429825e-001  8.5657895e-001  2.7324561e-001 ...\r\n%         0.0000000e+000  0.0000000e+000];\r\n%     yi = interp1(x, y, xi, 'pchip');\r\n%\r\n% Maxim has included several examples, a couple of which involve graphical\r\n% user interfaces. He also has a YouTube <http:\/\/youtu.be\/cjej0nf0fcY % video> of it in action. Thanks for a very useful tool, Maxim!\r\n%\r\n% *Comments*\r\n%\r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=3348#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/35056-interactive-curve-class#comments % comment> for Maxim.\r\n\r\n##### SOURCE END ##### 1f4bbcfbe76a476b8da347ddadf40f61\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n\r\nJiro's pick this week is Interactive Curve Class by Maxim Vedenyov.\r\n\r\nHave you ever wanted to create a test data set that you could use to test your program? I've used functions like rand and... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/02\/24\/interactive-curve-class\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3348"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=3348"}],"version-history":[{"count":11,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3348\/revisions"}],"predecessor-version":[{"id":7263,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3348\/revisions\/7263"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=3348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=3348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=3348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}