MATLAB Answers

Problem with origin and plotting axes

11 views (last 30 days)
Tarjei
Tarjei on 10 Feb 2011
Hi, I've been having problems with the plotting axes when it comes to plotting 2D points in MatLab (r2010a).
On a simple test program like:
W=[[0 0]' [0 1]' [1 0]' [1 1]'];
for i=1:4;
plot(W(:,i));
end
The origin is translated to (0,1). I've of course tried all the "normal" ways of setting axes, but the problem is still there. Anyone had similar problems, or may know of some default variables I could change to solve this rather irritating time spender?
Thanks for any help!

  0 Comments

Sign in to comment.

Accepted Answer

Brett Shoelson
Brett Shoelson on 10 Feb 2011
Is this what you're looking for?
>> x = [-0.5 0.5 0.5 -0.5];
>> y = [-0.5 -0.5 0.5 0.5];
>> plot(x,y,'ro')
>> axis([-1 1 -1 1]); %OR: set(gca,'xlim',[-1 1],'ylim',[-1 1])
Cheers,
Brett

  0 Comments

Sign in to comment.

More Answers (1)

Davide Ferraro
Davide Ferraro on 10 Feb 2011
Your code is basically:
plot([1 1]');
and is represented by a line with first point(1,1) and second point (2,1) (giving only y values, the x are placed automatically incrementally from 1).
If you want to display also the (0,0) coordinate you can simply use the AXIS command:
axis([0 2 0 2])

  1 Comment

Tarjei
Tarjei on 10 Feb 2011
Thanks for the answer, I see now that I didn't know about the automatic increment, but it is not exactly what I was looking for;
Lets say I want to display four corners of a square centered at the origin with side length 1.
I do not wish for it to be translated to start in (0,1).
Do you have any tricks?

Sign in to comment.

Sign in to answer this question.


Translated by