フィルターのクリア

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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by