Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
rectangle with exact dimension...

Subject: rectangle with exact dimension...

From: Ollie chen

Date: 9 Jan, 2011 01:57:04

Message: 1 of 11

hello newsreaders

I was wondering how to draw a rectangle with exact dimension

for example, I draw a rectangle with is 5(H) x 10(W)

if I want the rectangle to be 5cm x 10cm when printed out

what extra command should I use ?

because when I printed out, the size is not what I designed

many thanks

Subject: rectangle with exact dimension...

From: I am too much me

Date: 9 Jan, 2011 02:45:43

Message: 2 of 11

On 08/01/11 7:57 PM, Ollie chen wrote:

> I was wondering how to draw a rectangle with exact dimension
>
> for example, I draw a rectangle with is 5(H) x 10(W)
>
> if I want the rectangle to be 5cm x 10cm when printed out
>
> what extra command should I use ?
>
> because when I printed out, the size is not what I designed

Use 'Units', 'cm' for the graphical objects, and look at the
PaperPosition and PaperPositionMode figure properties.

If it doesn't work straight off for you, you should probably consider
using the Matlab File Exchange (FEX) contribution "export_fig".

Subject: rectangle with exact dimension...

From: Ollie chen

Date: 9 Jan, 2011 09:09:05

Message: 3 of 11

hello

my code is like this

set(gcf,'Units','centimeters');
set(gcf,'PaperUnits','centimeters');
set(gcf,'PaperPosition',[0 0 10 5]);
set(gcf,'PaperPositionMode','manual ');

rectangle('Position',[0 0 5 3]);
axis equal
axis off

and the printing preview is like this

http://img64.imageshack.us/img64/4224/clipboard01h.png

MATLAB did set the figure size to 10cm x 5cm

what my rectangle is messed up, it's not 5cm x 3cm

any ideas ?

thanks!

I am too much me <roberson@hushmail.com> wrote in message <rj9Wo.33934$sx4.19319@newsfe02.iad>...
> On 08/01/11 7:57 PM, Ollie chen wrote:
>
> > I was wondering how to draw a rectangle with exact dimension
> >
> > for example, I draw a rectangle with is 5(H) x 10(W)
> >
> > if I want the rectangle to be 5cm x 10cm when printed out
> >
> > what extra command should I use ?
> >
> > because when I printed out, the size is not what I designed
>
> Use 'Units', 'cm' for the graphical objects, and look at the
> PaperPosition and PaperPositionMode figure properties.
>
> If it doesn't work straight off for you, you should probably consider
> using the Matlab File Exchange (FEX) contribution "export_fig".

Subject: rectangle with exact dimension...

From: Husam Aldahiyat

Date: 9 Jan, 2011 09:42:05

Message: 4 of 11

Try

set(gca,'Units','centimeters');

Subject: rectangle with exact dimension...

From: Husam Aldahiyat

Date: 9 Jan, 2011 09:48:06

Message: 5 of 11

"Husam Aldahiyat" wrote in message <igbvtd$l8j$1@fred.mathworks.com>...
> Try
>
> set(gca,'Units','centimeters');

Disregard that.

Subject: rectangle with exact dimension...

From: Husam Aldahiyat

Date: 9 Jan, 2011 11:00:21

Message: 6 of 11

"Ollie chen" <olliekr@gmail.com> wrote in message <igbtvh$ipf$1@fred.mathworks.com>...
> hello
>
> my code is like this
>
> set(gcf,'Units','centimeters');
> set(gcf,'PaperUnits','centimeters');
> set(gcf,'PaperPosition',[0 0 10 5]);
> set(gcf,'PaperPositionMode','manual ');
>
> rectangle('Position',[0 0 5 3]);
> axis equal
> axis off
>
> and the printing preview is like this
>
> http://img64.imageshack.us/img64/4224/clipboard01h.png
>
> MATLAB did set the figure size to 10cm x 5cm
>
> what my rectangle is messed up, it's not 5cm x 3cm
>
> any ideas ?
>
> thanks!
>
> I am too much me <roberson@hushmail.com> wrote in message <rj9Wo.33934$sx4.19319@newsfe02.iad>...
> > On 08/01/11 7:57 PM, Ollie chen wrote:
> >
> > > I was wondering how to draw a rectangle with exact dimension
> > >
> > > for example, I draw a rectangle with is 5(H) x 10(W)
> > >
> > > if I want the rectangle to be 5cm x 10cm when printed out
> > >
> > > what extra command should I use ?
> > >
> > > because when I printed out, the size is not what I designed
> >
> > Use 'Units', 'cm' for the graphical objects, and look at the
> > PaperPosition and PaperPositionMode figure properties.
> >
> > If it doesn't work straight off for you, you should probably consider
> > using the Matlab File Exchange (FEX) contribution "export_fig".

Does this work?

set(gca,'units','cent')
pp = get(gca,'position');
xlim([0,pp(3)])
ylim([0,pp(4)])

Subject: rectangle with exact dimension...

From: Ollie chen

Date: 9 Jan, 2011 12:13:05

Message: 7 of 11

oh my god !

your code works !!

thanks you so much !!

the output rectangle is 5.0036cm x 3.0016cm

think this is precise enough !

you just solve a problem that troubles me for a week !

"Husam Aldahiyat" wrote in message <igc4g5$9tg$1@fred.mathworks.com>...
> "Ollie chen" <olliekr@gmail.com> wrote in message <igbtvh$ipf$1@fred.mathworks.com>...
> > hello
> >
> > my code is like this
> >
> > set(gcf,'Units','centimeters');
> > set(gcf,'PaperUnits','centimeters');
> > set(gcf,'PaperPosition',[0 0 10 5]);
> > set(gcf,'PaperPositionMode','manual ');
> >
> > rectangle('Position',[0 0 5 3]);
> > axis equal
> > axis off
> >
> > and the printing preview is like this
> >
> > http://img64.imageshack.us/img64/4224/clipboard01h.png
> >
> > MATLAB did set the figure size to 10cm x 5cm
> >
> > what my rectangle is messed up, it's not 5cm x 3cm
> >
> > any ideas ?
> >
> > thanks!
> >
> > I am too much me <roberson@hushmail.com> wrote in message <rj9Wo.33934$sx4.19319@newsfe02.iad>...
> > > On 08/01/11 7:57 PM, Ollie chen wrote:
> > >
> > > > I was wondering how to draw a rectangle with exact dimension
> > > >
> > > > for example, I draw a rectangle with is 5(H) x 10(W)
> > > >
> > > > if I want the rectangle to be 5cm x 10cm when printed out
> > > >
> > > > what extra command should I use ?
> > > >
> > > > because when I printed out, the size is not what I designed
> > >
> > > Use 'Units', 'cm' for the graphical objects, and look at the
> > > PaperPosition and PaperPositionMode figure properties.
> > >
> > > If it doesn't work straight off for you, you should probably consider
> > > using the Matlab File Exchange (FEX) contribution "export_fig".
>
> Does this work?
>
> set(gca,'units','cent')
> pp = get(gca,'position');
> xlim([0,pp(3)])
> ylim([0,pp(4)])

Subject: rectangle with exact dimension...

From: Husam Aldahiyat

Date: 9 Jan, 2011 12:25:20

Message: 8 of 11

Haha, I'm glad it worked.

But how did you measure the rectangle side lengths to that precision?

Subject: rectangle with exact dimension...

From: Ollie chen

Date: 9 Jan, 2011 13:54:05

Message: 9 of 11

I output in illustrator format

and there's a tool that measures the size

it will exactly match the printed out result

"Husam Aldahiyat" wrote in message <igc9fg$km7$1@fred.mathworks.com>...
> Haha, I'm glad it worked.
>
> But how did you measure the rectangle side lengths to that precision?

Subject: rectangle with exact dimension...

From: Jenny

Date: 6 Jul, 2014 13:47:07

Message: 10 of 11

"Ollie chen" <olliekr@gmail.com> wrote in message <igcels$g9g$1@fred.mathworks.com>...
> I output in illustrator format
>
> and there's a tool that measures the size
>
> it will exactly match the printed out result
>
> "Husam Aldahiyat" wrote in message <igc9fg$km7$1@fred.mathworks.com>...
> > Haha, I'm glad it worked.
> >
> > But how did you measure the rectangle side lengths to that precision?

Hello everyone,

my code is as follows:

b = 0.00162823818984831; % is the length of 0,08 cm according to createfigure
h = 0.0119632658580434; % is the length of 0,2 cm according to createfigure

color = [1 0 0];

x = 0;
y = 0;

U0 = 3+b;
L0 = 5;

set(gcf,'Units','centimeters');
set(gcf,'PaperUnits','centimeters');
axis equal
axis off

for Bewegung_in_y_Richtung = 1:L0
  for Wiederholung10 = 1:2
    for Bewegung_in_x_Richtung = 1:U0
      rectangle ('Position', [x,y,b,h], 'FaceColor', color)
      x = x + b;
    end
    rectangle ('Position', [x,y,b,h], 'FaceColor', [1 1 0])
    x = x + b;
  end
  x = 0;
  y = y + h;
end

What I would like is that every single rectangle would have the dimension of 0.08 cm in the x-direction and 0.2 cm in the y-direction. Even if I change the dimensions of U0 and L0. When I previously plotted everything and measured it with the means of Illustrator, I got completely different dimensions.

So far I have tried these settings:
% Set (gcf, 'Position Paper', [0 0 x y]);
% Set (gcf, 'Position Paper Fashion', 'manual');

what has not helped me. I've tried using the dpi settings, but I could't figure out the connection.

It would be perfect when the plot has exactly the dimensions as the result is, so no white on the corners. Is there a way to do so?

Can someone help me?

Subject: rectangle with exact dimension...

From: Jenny

Date: 6 Jul, 2014 13:48:08

Message: 11 of 11

"Ollie chen" <olliekr@gmail.com> wrote in message <igcels$g9g$1@fred.mathworks.com>...
> I output in illustrator format
>
> and there's a tool that measures the size
>
> it will exactly match the printed out result
>
> "Husam Aldahiyat" wrote in message <igc9fg$km7$1@fred.mathworks.com>...
> > Haha, I'm glad it worked.
> >
> > But how did you measure the rectangle side lengths to that precision?

Hello everyone,

my code is as follows:

b = 0.00162823818984831; % is the length of 0,08 cm according to createfigure
h = 0.0119632658580434; % is the length of 0,2 cm according to createfigure

color = [1 0 0];

x = 0;
y = 0;

U0 = 3+b;
L0 = 5;

set(gcf,'Units','centimeters');
set(gcf,'PaperUnits','centimeters');
axis equal
axis off

for Bewegung_in_y_Richtung = 1:L0
  for Wiederholung10 = 1:2
    for Bewegung_in_x_Richtung = 1:U0
      rectangle ('Position', [x,y,b,h], 'FaceColor', color)
      x = x + b;
    end
    rectangle ('Position', [x,y,b,h], 'FaceColor', [1 1 0])
    x = x + b;
  end
  x = 0;
  y = y + h;
end

What I would like is that every single rectangle would have the dimension of 0.08 cm in the x-direction and 0.2 cm in the y-direction. Even if I change the dimensions of U0 and L0. When I previously plotted everything and measured it with the means of Illustrator, I got completely different dimensions.

So far I have tried these settings:
% Set (gcf, 'Position Paper', [0 0 x y]);
% Set (gcf, 'Position Paper Fashion', 'manual');

what has not helped me. I've tried using the dpi settings, but I could't figure out the connection.

It would be perfect when the plot has exactly the dimensions as the result is, so no white on the corners. Is there a way to do so?

Can someone help me?

Tags for this Thread

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.

Contact us