我希望网格中包含这样的行:
目前,我编码得到这样的网格:
我只需在其中添加水平和垂直线。
MyCode:
[X,Y] = meshgrid(-1:0.1:1, -1:0.1:1);
X = X(:);
Y = Y(:);
plot(X,Y,'b.');
xlabel('X'); % // Label the X and Y axes
ylabel('Y');
title('Initial Grid');
答案 0 :(得分:2)
要绘制这些线条,最简单的方法是两个循环:
x = -1:0.1:1;
y = -1:0.1:1;
hold on
for n = 1:numel(x); %// loop over vertical lines
plot([x(n) x(n)], [y(1) y(end)], 'k-'); %// change 'k-' to whatever you need
end
for n = 1:numel(y); %// loop over horizontal lines
plot([x(1) x(end)], [y(n) y(n)], 'k-'); %// change 'k-' to whatever you need
end
或者,您可以使用grid
;但是你不能控制线型。你得到黑色虚线:
x = -1:0.1:1;
y = -1:0.1:1;
figure
set(gca,'xtick',x);
set(gca,'ytick',y);
axis([min(x) max(x) min(y) max(y)])
grid on