Don't want my points on the boundary

1 view (last 30 days)
This code puts my points on the boundary of the plot , which
I don't want. Have tried setting xlim large, and various
other approaches. Any enlargement would help.
close all;
s = 2;
ss = -s:s;
[x,y] = meshgrid(ss);
plot(x,y,'ko');
hold on;
xticks([-s-1:s+1])
  4 Comments
Alex Mcaulley
Alex Mcaulley on 30 Apr 2019
This code should work:
s = 2;
ss = -s:s;
[x,y] = meshgrid(ss);
plot(x,y,'ko');
hold on;
xlim([-3,3])
ylim([-3,3])
xticks(ss)
yticks(ss)
tonteria.png
David Epstein
David Epstein on 30 Apr 2019
@Alex Mcaulley: If you want to turn your code as an Answer, and add a caution about clearing variables and closing images, I will upvote/accept or whatever. When I tried your code and it still didn't work on my machine, I suddenly twigged. I then preceded your code with
close all; clear all
and then, hallelujah!!, it worked as expected.
Explanation: I had early misused xlim, and Matlab was convinced it was the name of an array,
rather than a function. Would have been nice if Matlab had issued a warning.

Sign in to comment.

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 30 Apr 2019
Here we are:
s = 2;
ss = -s:s;
[x,y] = meshgrid(ss);
plot(x,y,'ko');
hold on;
xlim([-3,3])
ylim([-3,3])
xticks(ss)
yticks(ss)

More Answers (1)

KSSV
KSSV on 30 Apr 2019
s = 2;
dx = 0.5 ; % can be changed to your desired offset
ss = -s+dx:s-dx;
[x,y] = meshgrid(ss);
plot(x,y,'ko');
hold on;
xticks([-s-1:s+1])
  2 Comments
David Epstein
David Epstein on 30 Apr 2019
This gives x with non-integer entries.
Also, when I specify the ticks and the x and y values
I want all of these to be visible on the plot, with the (x,y) points not on the boundary
David Epstein
David Epstein on 30 Apr 2019
@KSSV: your answer points to a possible solution by using invisible points. This would presumably work (I haven't yet tried it), but, in my opinion, if such a solution is necessary, it would show a defect in Matlab.

Sign in to comment.

Categories

Find more on Formatting and Annotation in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!