Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在matlab中修改网格_Matlab - Fatal编程技术网

在matlab中修改网格

在matlab中修改网格,matlab,Matlab,我希望网格中有这样的线: 目前,我已经编写了如下代码: 我只需要在其中添加水平线和垂直线 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'); 要绘制这些线,最简单的方法是两个循环: x = -1:0.1:1; y = -1:0

我希望网格中有这样的线:

目前,我已经编写了如下代码:

我只需要在其中添加水平线和垂直线

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');

要绘制这些线,最简单的方法是两个循环:

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


或者,你可以使用;但是你不能控制线型。您将看到黑色虚线:

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

嗯。。。我知道我从某处认出了那个代码:)