필터 지우기
필터 지우기

Don't want my points on the boundary

조회 수: 1 (최근 30일)
David Epstein
David Epstein 2019년 4월 30일
댓글: Alex Mcaulley 2019년 4월 30일
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
Alex Mcaulley
Alex Mcaulley 2019년 4월 30일
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 2019년 4월 30일
@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.

댓글을 달려면 로그인하십시오.

채택된 답변

Alex Mcaulley
Alex Mcaulley 2019년 4월 30일
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
Alex Mcaulley
Alex Mcaulley 2019년 4월 30일
Probably you had any definition as:
xlim = [-3,3]

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2019년 4월 30일
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
David Epstein
David Epstein 2019년 4월 30일
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 2019년 4월 30일
@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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by