{"id":1341,"date":"2014-02-19T09:50:24","date_gmt":"2014-02-19T14:50:24","guid":{"rendered":"https:\/\/blogs.mathworks.com\/videos\/?p=1341"},"modified":"2014-02-19T09:50:24","modified_gmt":"2014-02-19T14:50:24","slug":"uicontextmenu-and-buttondownfcn-in-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/videos\/2014\/02\/19\/uicontextmenu-and-buttondownfcn-in-matlab\/","title":{"rendered":"uicontextmenu and ButtonDownFcn in MATLAB"},"content":{"rendered":"When you use ButtonDownFcn in MATLAB, your callback is given an automatic input called hObject.  This hObject is the handle of the object that you interacted with to invoke the callback, which makes it easy to define behavior based on the selected object.\r\n\r\nThis is a little trickier when working with uicontextmenu, since the context menu itself is reported as the selected object. This video explains the behavior and shows one way to get the handle to the actual object the user selected. This is an advanced topic that assumes you know about <a href=\"https:\/\/blogs.mathworks.com\/videos\/2008\/01\/28\/practical-example-adding-callbacks-to-a-plot\/\">callbacks<\/a> and <a href=\"https:\/\/blogs.mathworks.com\/videos\/2011\/02\/15\/context-menus-in-an-amortization-application-in-matlab\/\">UiContextMenu<\/a>.\r\n\r\n\r\n<div><div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"3877304428001\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div>\r\n <\/div>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"thumbnail thumbnail_asset asset_overlay video\"><a href=\"https:\/\/blogs.mathworks.com\/videos\/2014\/02\/19\/uicontextmenu-and-buttondownfcn-in-matlab\/?dir=autoplay\"><img decoding=\"async\" src=\"https:\/\/cf-images.us-east-1.prod.boltdns.net\/v1\/static\/62009828001\/b2d969d9-159e-4232-935c-98599f06fdbb\/cb968e3e-8f53-409b-98dc-74a4013e11c1\/1280x720\/match\/image.jpg\" onError=\"this.style.display ='none';\"\/>\n      <div class=\"overlay_container\">\n      <span class=\"icon-video icon_color_null\"><time class=\"video_length\">4:01<\/time><\/span>\n      <\/div>\n      <\/a><\/div><p>When you use ButtonDownFcn in MATLAB, your callback is given an automatic input called hObject.  This hObject is the handle of the object that you interacted with to invoke the callback, which makes&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/videos\/2014\/02\/19\/uicontextmenu-and-buttondownfcn-in-matlab\/\">read more >><\/a><\/p>","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,12],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/1341"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/comments?post=1341"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/1341\/revisions"}],"predecessor-version":[{"id":1358,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/1341\/revisions\/1358"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/media?parent=1341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/categories?post=1341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/tags?post=1341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}