Don't want my points on the boundary

1 vue (au cours des 30 derniers jours)
David Epstein
David Epstein le 30 Avr 2019
Commenté : Alex Mcaulley le 30 Avr 2019
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 commentaires
Alex Mcaulley
Alex Mcaulley le 30 Avr 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 le 30 Avr 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.

Connectez-vous pour commenter.

Réponse acceptée

Alex Mcaulley
Alex Mcaulley le 30 Avr 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)
  1 commentaire
Alex Mcaulley
Alex Mcaulley le 30 Avr 2019
Probably you had any definition as:
xlim = [-3,3]

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 30 Avr 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 commentaires
David Epstein
David Epstein le 30 Avr 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 le 30 Avr 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Formatting and Annotation dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by