-1

I have to linearise a zig-zag line in matlab. I have used the 'line' command of matlab to generate a tilt line but it is not smooth. Can anyone help me.

I now use the following code

len = 3;
wid = 1;
ly  = 1;
lx  = 0.5;
th  = 60;
vertices = [lx      ly;
            lx+wid  ly;
            lx+wid  ly+len;
            lx      ly+len;
            lx      ly];
R=[ cos(th) sin(th);
   -sin(th) cos(th)];
w   = vertices*R;
wx1 = w(:,1);
wx1 = wx1';
wy1 = w(:,2);
wy1 = wy1';
h=line(wx1,wy1,'color','black');
axis([-10 10 -10 10])
axis off
Gunther Struyf
  • 11,158
  • 2
  • 34
  • 58
Shayan Ali
  • 65
  • 2
  • 16

2 Answers2

0

You draw a square by setting the four corner vertices. If you mean that is doesn't look like a square in the resulting plot, it is because you x- and y-axis do not have the same scaling.

You set the x- and y-limits to be the same

axis([-10 10 -10 10])

But this doesn't guarantee same scaling, since the figure itself can have different width as height.

However you do can enforce the scaling to be alike

axis equal
Gunther Struyf
  • 11,158
  • 2
  • 34
  • 58
  • what do you mean then with "the line isn't smooth" Can you prodcue an image where you indicate your actual problem? _It isn't clear at all!_ You can always upload an image to other online services ([click here](http://www.google.com/search?q=image+upload)) and provide the link here. – Gunther Struyf Jun 07 '12 at 08:30
  • 1
    err, that's just [jaggies](http://en.wikipedia.org/wiki/Jaggies). I assume you saved the figure as a jpeg or something and then zoomed in.. Non-vector image formats will always have this problem, if you zoom in in the matlab figure itself, you won't have this effect, because matlab redraws the (vector) images (=infinite sharpness); Or you could save the image in a vector format (eps, pdf,...) – Gunther Struyf Jun 07 '12 at 09:33
  • 1
    It's physically impossible to create infintely smooth edges using a non-vector format. Jpeg only saves the color of each point in a rectangular grid, so if your lines aren't perfect horizontal or vertical, those jagged edges will allways appear if you zoom in on the figure. If you save at higher resolution, you can just zoom a little bit longer before your eyes can see the jagging. In fact, your monitor itself also produces that jagged look (it's essentially a grid of colored dots). – Gunther Struyf Jun 07 '12 at 10:23
  • What transformation are you talking about? It looks like that is the problem, if it can't account for (always present) jaggies in angled straight lines in common image formats, then that's the issue. Or you have to save your image with a higher resolution. Or first zoom in on the matlab figure, and only save it when your done zooming. But please, also enlighten us about this transformation you're talking about. – Gunther Struyf Jun 07 '12 at 15:37
  • http://stackoverflow.com/questions/5212573/saving-matlab-graphs-in-a-specific-resolution here is explained how to save in higher resolution – Gunther Struyf Jun 07 '12 at 16:12
  • Thanx for the help. i will try it and then let you know. – Shayan Ali Jun 07 '12 at 17:16
0

Judging by your image, it looks like there was anti-aliasing applied on the line. It must have happened when you saved your plot to bitmap/JPEG. Probably, the image you are seeing on the axes is smooth.

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104