Don't want my points on the boundary

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
Alex Mcaulley
Alex Mcaulley il 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 il 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.

Accedi per commentare.

Risposta accettata

Alex Mcaulley
Alex Mcaulley il 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)

Più risposte (1)

KSSV
KSSV il 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 Commenti
David Epstein
David Epstein il 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 il 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.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by