Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: how to draw an irregular shape on GUI axes?

Subject: how to draw an irregular shape on GUI axes?

From: Kathleen

Date: 02 Aug, 2007 20:02:45

Message: 1 of 8

Hi! I am creating a GUI (using Matlab and GUIDE), and I
would like to draw a static, irregularly-shaped object on
my axes. From all of the Matlab documentation I've seen,
it is only possible to plot rectangles and ovals, but
nothing else.

Is my only option to overlay a large series of rectangles
& ovals to create my desired shape (if this is even
possible), or does someone know of a way to create a
static irregular shape easily?

Thanks for your help! Kathleen



Subject: Re: how to draw an irregular shape on GUI axes?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 02 Aug, 2007 20:27:24

Message: 2 of 8

In article <f8td95$i7t$1@fred.mathworks.com>,
Kathleen <quisquiliae2@hotmail.com> wrote:
>Hi! I am creating a GUI (using Matlab and GUIDE), and I
>would like to draw a static, irregularly-shaped object on
>my axes. From all of the Matlab documentation I've seen,
>it is only possible to plot rectangles and ovals, but
>nothing else.

>Is my only option to overlay a large series of rectangles
>& ovals to create my desired shape (if this is even
>possible), or does someone know of a way to create a
>static irregular shape easily?

If it is static, you could possibly draw it into an image
and display the image.

If it is a filled polygon, you can use fill().

You can use plot() to create line plots; if you issued
a 'hold on' command, then the next plot would add to the
existing plot rather than erasing.

If it is a filled polygon, you can use patch()
--
Programming is what happens while you're busy making other plans.

Subject: Re: how to draw an irregular shape on GUI axes?

From: Kathleen

Date: 02 Aug, 2007 20:49:33

Message: 3 of 8

Thanks for your reply, Walter.

I have tried the following code:

    X = {-0.5, -0.2,-0.1,-0.4, -0.6, -0.5};
    Y = {-0.15, 0.1, 0.4, 0.5, 0.2, -0.15};
    patch(X, Y, 'c');

within my draw_plot() function and tried fill() as well.
However, for both patch() and fill() function calls, I get
the error:

??? Error using ==> patch [or fill]
Conversion to double from cell is not possible.

As far as I can tell, my code above should work. Any
suggestions about what I might be doing wrong?

Thanks a lot! :) Kathleen
 

Subject: Re: how to draw an irregular shape on GUI axes?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 02 Aug, 2007 22:21:11

Message: 4 of 8

In article <f8tg0t$46b$1@fred.mathworks.com>,
Kathleen <quisquiliae2@hotmail.com> wrote:

>I have tried the following code:

> X = {-0.5, -0.2,-0.1,-0.4, -0.6, -0.5};
> Y = {-0.15, 0.1, 0.4, 0.5, 0.2, -0.15};
> patch(X, Y, 'c');

>within my draw_plot() function and tried fill() as well.
>However, for both patch() and fill() function calls, I get
>the error:

>??? Error using ==> patch [or fill]
>Conversion to double from cell is not possible.

>As far as I can tell, my code above should work. Any
>suggestions about what I might be doing wrong?

Use arrays instead of cells.
X = [-0.5, -0.2,-0.1,-0.4, -0.6, -0.5];
Y = [-0.15, 0.1, 0.4, 0.5, 0.2, -0.1];

patch() and fill() are defined over matrices, not over cell arrays.
--
Programming is what happens while you're busy making other plans.

Subject: Re: how to draw an irregular shape on GUI axes?

From: us

Date: 02 Aug, 2007 22:35:27

Message: 5 of 8

Kathleen:
<SNIP down to syntax error...

> X = {-0.5, -0.2,-0.1,-0.4, -0.6, -0.5};
> Y = {-0.15, 0.1, 0.4, 0.5, 0.2, -0.15};
> patch(X, Y, 'c');

must read

     x={-0.5, -0.2,-0.1,-0.4, -0.6, -0.5};
     y={-0.15, 0.1, 0.4, 0.5, 0.2, -0.15};
     patch([x{:}],[y{:}],'c');

us

Subject: Re: how to draw an irregular shape on GUI axes?

From: Kathleen

Date: 03 Aug, 2007 14:49:38

Message: 6 of 8

Awesome! Now my polygon appears on my axes.

One more question: I have an animated object that needs to
be visible *over* the polygon (i.e., polygon needs to be
in the background). Right now, the polygon covers and
obscures the animation.

How can I layer these objects so that the polygon shape is
in the background?

Thanks! Kathleen

Subject: Re: how to draw an irregular shape on GUI axes?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 03 Aug, 2007 15:28:45

Message: 7 of 8

In article <f8vfa2$9ar$1@fred.mathworks.com>,
Kathleen <quisquiliae2@hotmail.com> wrote:

>One more question: I have an animated object that needs to
>be visible *over* the polygon (i.e., polygon needs to be
>in the background). Right now, the polygon covers and
>obscures the animation.

>How can I layer these objects so that the polygon shape is
>in the background?

The newest object (that is, constructed more recently)
is the one that will be displayed on top.

See also the documentation on uistack()

Also, I can't think right at the second of exactly which page this
is documented on, but you can set the Children property of
handle graphics objects to change the order they stack in.
When you get() the Children property, the first child in the list
will be the one that appears on top, so to change the order,
set() the Children property to an appropriate permutation of
the original.
--
  Prototypes are supertypes of their clones. -- maplesoft

Subject: Re: how to draw an irregular shape on GUI axes?

From: Kathleen

Date: 03 Aug, 2007 15:37:36

Message: 8 of 8

Thanks for your reply, Walter. I will investigate based on
your advice. (Note: a few minutes ago I posted this same
question as a new thread, thinking it would be better to
separate topics.)

Curiously, I draw the polygon as the very first object
within my OpeningFcn, yet when the animation appears, it's
still layered underneath. Weird! I will try working with
uistack() and get().

Thanks! Kathy


 

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
animation Kathleen 03 Aug, 2007 10:55:25
axes Kathleen 03 Aug, 2007 10:55:25
layering Kathleen 03 Aug, 2007 10:55:25
code us 02 Aug, 2007 18:40:25
cell us 02 Aug, 2007 18:40:25
syntax us 02 Aug, 2007 18:40:25
guide Kathleen 02 Aug, 2007 16:05:04
gui Kathleen 02 Aug, 2007 16:05:04
draw irregular shape Kathleen 02 Aug, 2007 16:05:04
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics