Using imline with uiaxes

303 views Asked by At

I am trying to design an app using Matlab 2017b with appdesigner. I want to attach a movable line to an image using the imline function. However, appdesigner appear to use a new type of object, uiaxes, whereas the imline function will only use the object axes.

Example of command that does work:

figure; taxes = axes;  imline(taxes, [0 0], [0 1]);

Example of a command that does not work:

figure; tuiaxes = uiaxes;  imline(tuiaxes, [0 0], [0 1]);

Questions

Is there a workaround for using imline with appdesigner? Is it still possible to use the old axes object? Is there some other way to have interactive lines on GUIs using the appdesigner?

1

There are 1 answers

2
Dev-iL On BEST ANSWER

To access the underlying "old axes object" of a uiaxes, all we need to do is struct(tuiaxes).Axes. Moving on - I tried playing around with this in R2018b, and I have some good and some bad news.

  • The good news is that one can add a imline to a MATLAB figure by modifying the imline function (<MATLAB>\R2018b\toolbox\images\imuitools\imline.m) function a bit.
  • The bad news is that it will not have most of the functionality that you might be used to.

Here are the very basic steps:

  1. Create a copy of imline.m, let's call it ui_imline.m.
  2. Comment out lines 260-261 (related to cmenu), and line 317 (updateAncestorListeners(...)).
  3. Modify your code as follows:

    uifigure; tuiaxes = uiaxes; ui_imline(struct(tuiaxes).Axes, [0 0], [0 1]);
    

This will result in:

enter image description here

If you want any other functionality besides dragging, you'll likely have to rewrite all uifigure-incompatible bits of imline yourself, or wait for an unknown future release that would do it for you.