1

I'm trying to implement a buttondownfcn callback in an app I'm building use AppDesigner.

There is a plot that my code generates and I want to click on the plot and have some code execute.

The problem is when I try to use buttondownfcn I get a message saying there may be some incompatibility with UIFigure objects, which is what the object is classified as when AppDesigner creates it.

Maybe I'm doing something wrong? Has anyone had the same issue or know of a way to work around it?

thanks

Kumar
  • 31
  • 5
  • App Designer utilizes new graphics objects (e.g. [`uifigure`](https://www.mathworks.com/help/matlab/ref/uifigure.html) and [`uiaxes`](https://www.mathworks.com/help/matlab/ref/uiaxes.html)) whose functionality is not yet totally in line with that of the "legacy" objects (e.g. [`figure`](https://www.mathworks.com/help/matlab/ref/figure.html) and [`axes`](https://www.mathworks.com/help/matlab/ref/uifigure.html)). You'll need to create your GUI programmatically in order to utilize the legacy components. – sco1 Feb 27 '17 at 19:56
  • Because App Designer *is* nice to use for laying out components, you could do as much work as you could there and then convert the code. The class definition App Designer generates is fairly straightforward to modify, and there are things like [`mlapp2classdef`](https://github.com/StackOverflowMATLABchat/mlapp2classdef) (full disclosure: I wrote this primarily as a proof-of-concept) that can do some of the work for you. – sco1 Feb 27 '17 at 20:10
  • I've tried using that program but every time I convert my code and try to run it I get a directory error (even though the converted file is placed in the same directory). Also, when I change anything in the new m file, it seems like the original code is run and MATLAB ignores my changes. Whats going on? – Kumar Mar 30 '17 at 22:15
  • First question: I have no way to answer this without more details, if the function converted correctly then the issue is with your code. Second question: see [function precedence order](https://www.mathworks.com/help/matlab/matlab_prog/function-precedence-order.html). Note that `*.mlapp` has a higher precedence than `*.m`. Move them to different folders. – sco1 Mar 31 '17 at 19:39
  • Update: I cleared my workspace and deleted the mlapp2classdef in the directory that it creates the m file. Now, running the m file gives me this error: `While setting property 'UIAxes' of class 'testclick': Value must be 'matlab.ui.control.UIAxes'.` testclick is the name of the m file. It locates the error on the line where the code says `app.UIAxes = axes(app.UIFigure)` – Kumar Mar 31 '17 at 20:42
  • For potential issues with my code please submit an issue to the project and include a **reproducible** example. – sco1 Apr 03 '17 at 13:37
  • There is a hackable way to do this using JavaScript and and some undocumented approaches. The essence of the solution would be to capture the clicks using JavaScript and report the position to Matlab through a invisible button callback. See this post by [Iliya Romm](https://undocumentedmatlab.com/blog/matlab-callbacks-for-uifigure-javascript-events) – Khlick Aug 29 '18 at 02:09

0 Answers0