{"id":2467,"date":"2009-09-25T11:51:36","date_gmt":"2009-09-25T11:51:36","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/09\/25\/lassom\/"},"modified":"2009-09-25T11:51:36","modified_gmt":"2009-09-25T11:51:36","slug":"lassom","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/09\/25\/lassom\/","title":{"rendered":"lasso.m"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021\">Bob<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/3991-lasso-m\">lasso.m<\/a> by Thomas Rutten.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>Suppose you have a set of XY points. You plot them to see how they spread out. You decide a certain clump of points is special.\r\n      How do you get MATLAB to know which points you care about? With <tt>lasso<\/tt> you can select them with your mouse!\r\n   <\/p>\r\n   <p>To demonstrate I will use the sunspot example data that ships with MATLAB.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">load <span style=\"color: #A020F0\">sunspot.dat<\/span>\r\n[x,y,i] = lasso(sunspot(:,1),sunspot(:,2))<\/pre><pre style=\"font-style:oblique\">press a KEY to start selection by mouse, LEFT mouse button for selection, RIGHT button closes loop\r\nx =\r\n        1836\r\n        1837\r\n        1848\r\n        1870\r\ny =\r\n        121.5\r\n        138.3\r\n        124.7\r\n          139\r\ni =\r\n   137\r\n   138\r\n   149\r\n   171\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/pick_lasso_01.png\"> <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/pick_lasso_02.png\"> <pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">centroid = [mean(x) mean(y)]<\/pre><pre style=\"font-style:oblique\">centroid =\r\n       1847.8       130.88\r\n<\/pre><p>The program prompted me how to start and stop the selection. I left off the semicolon to show the values returned for further\r\n      analysis (ie, centroid calculation). The first plot shows the polygon region I selected. The second plot shows the selected\r\n      points with a free legend and point counter. Nice!\r\n   <\/p>\r\n   <p>Note: if you like graphically interacting with your XY points be sure to check out <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/rn\/brfrh4i-1.html#brfrh4i-2\">Data Brushing<\/a> introduced with R2008a.\r\n   <\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2467#respond\">Comments?<\/a><\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_0b99d4faa00a4756a6953e25014efb1a() {\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='0b99d4faa00a4756a6953e25014efb1a ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 0b99d4faa00a4756a6953e25014efb1a';\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 = 'Robert Bemis';\r\n        copyright = 'Copyright 2009 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<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>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_0b99d4faa00a4756a6953e25014efb1a()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.9<br><\/p>\r\n<\/div>\r\n<!--\r\n0b99d4faa00a4756a6953e25014efb1a ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021 Bob>'s \r\n% pick this week is \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/3991-lasso-m lasso.m> \r\n% by Thomas Rutten.\r\n%%\r\n% Suppose you have a set of XY points. You plot them to see how they spread\r\n% out. You decide a certain clump of points is special. How do you get MATLAB\r\n% to know which points you care about? With |lasso| you can select them with\r\n% your mouse! \r\n%%\r\n% To demonstrate I will use the sunspot example data that ships with MATLAB.\r\nload sunspot.dat\r\n[x,y,i] = lasso(sunspot(:,1),sunspot(:,2))\r\n%%\r\ncentroid = [mean(x) mean(y)]\r\n%%\r\n% The program prompted me how to start and stop the selection. I left off the\r\n% semicolon to show the values returned for further analysis (ie, centroid\r\n% calculation). The first plot shows the polygon region I selected. The\r\n% second plot shows the selected points with a free legend and point counter.\r\n% Nice!\r\n%%\r\n% Note: if you like graphically interacting with your XY points be sure to\r\n% check out \r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/rn\/brfrh4i-1.html#brfrh4i-2 Data Brushing>\r\n% introduced with R2008a.\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2467#respond Comments?>\r\n\r\n##### SOURCE END ##### 0b99d4faa00a4756a6953e25014efb1a\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Bob's pick this week is lasso.m by Thomas Rutten.\r\n      \r\n   \r\n   Suppose you have a set of XY points. You plot them to see how they spread out. You decide a... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/09\/25\/lassom\/\">read more >><\/a><\/p>","protected":false},"author":46,"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\/2467"}],"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\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2467"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2467\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}