MATLAB Answers

How to add a polygon to UIAxes in appdesigner?

41 views (last 30 days)
Kyle Millar
Kyle Millar on 10 May 2018
Commented: Kyle Millar on 15 May 2018
I currently can create a rectangle in the UIAxes with this code:
rect = rectangle(app.UIAxes, 'Position', [0 26 .13 98], 'FaceColor', 'r', 'EdgeColor', 'r');
but what if I want to define where each corner is in the axes. As in, not a rectangle or any other standard shape. I have looked into the patch object, but this code does not work:
X = [0 0 .13 .13]
Y = [26 124 124 26]
shape = patch(app.UIAxes, app.swathX, app.swathY, 'r');
How can I do that with UIAxes?

  2 Comments

Greg
Greg on 11 May 2018
"but this code does not work:"
How so? What does it do? How is that different from what you expect? Does it throw an error? Post the error if it does.
I would hope
X = [0 0 .13 .13]
Y = [26 124 124 26]
shape = patch(app.UIAxes, app.swathX, app.swathY, 'r');
throws some form of unknown variable/property error, as you define X and Y but use swathX and swathY.
Kyle Millar
Kyle Millar on 12 May 2018
In the third line, it should say X and Y. I forgot to change the variable names in the question. This is the error I get:
Error using patch
While setting property 'Parent' of class 'Patch':
Functionality not supported with UIAxes. For more information, see Graphics Support in App Designer.

Sign in to comment.

Answers (1)

Greg
Greg on 11 May 2018
ps = polyshape([0,0,.13,.13],[26,124,124,26]); % This is still a rectangle though...
pg = plot(uiaxes,ps);

  9 Comments

Show 6 older comments
Kyle Millar
Kyle Millar on 15 May 2018
I tried to use plot, but that was giving me more problems. I don’t think that would work. I realized I could accomplish the same thing I wanted with just filled rectangles and filled triangles, but it seems like MATLAB has no good way of adding triangles either. I may just scratch the MATLAB attempt, and try using a programming language where I can get more flexibility.
Sean de Wolski
Sean de Wolski on 15 May 2018
Is upgrading not an option? App designer is under active development so it gets a lot of new features with each release.
Kyle Millar
Kyle Millar on 15 May 2018
I'm not sure. I don't think so. It is a school license that has not ran out yet, but I just graduated. I don't know if I can upgrade it anymore.

Sign in to comment.

Sign in to answer this question.