Matlab 流线输出为空

Output of streamline in Matlab is empty

我想用流线来表示矢量场。向量场在一点上是奇异的。我想删除奇点附近的区域(例如到奇点的距离小于 1 的区域)。我写了下面的代码,但它没有显示任何内容。谁能帮帮我?

clear all;
close all;
r1 = 1; r2 = 5;  % Radii of your circles
x_0 = 0; y_0 = 0; % Centre of circles
[x,y] = meshgrid(x_0-r2:0.2:x_0+r2,y_0-r2:0.2:y_0+r2); % meshgrid of points

idx = ((x-x_0).^2 + (y-y_0).^2 > r1^2 & (x-x_0).^2 + (y-y_0).^2 < r2^2);
x = sort(x(idx));
[x, index] = unique(x);
y = sort(y(idx));
[y, index] = unique(y);
U=cos(x)/sqrt(x.^2+y.^2);
V=sin(x)/sqrt(x.^2+y.^2);
streamslice(x,y,U,V);

我认为您误解了 streamslice 的概念。这是你期待的吗?

close all;
r1 = 1; r2 = 5;  % Radii of your circles
x_0 = 0; y_0 = 0; % Centre of circles
[xx,yy] = meshgrid(x_0-r2:0.2:x_0+r2,y_0-r2:0.2:y_0+r2); % meshgrid of points

% idx = ((xx-x_0).^2 + (yy-y_0).^2 > r1^2 & (xx-x_0).^2 + (yy-y_0).^2 < r2^2);
% x = sort(xx(idx));
% [x, index] = unique(x);
% y = sort(yy(idx));
% [y, index] = unique(y);
U=cos(xx)./sqrt(xx.^2+yy.^2);
V=sin(xx)./sqrt(xx.^2+yy.^2);
streamslice(xx,yy,U,V);

你的代码的问题是 UV 都是零,所以你得到白色 space。原因是您不使用 ./ 的元素除法。所以作为第一步你应该写:

U = cos(x)./sqrt(x.^2+y.^2);
V = sin(x)./sqrt(x.^2+y.^2);

现在 UV 不是零,也不再是矩阵,因此它们不是 streamslice 的有效输入。原因是 xy 在调用时被转换为向量:

x = sort(x(idx));
y = sort(y(idx));

我猜你可以删除所有这些索引,然后简单地写:

r1 = 1; r2 = 5;  % Radii of your circles
x_0 = 0; y_0 = 0; % Centre of circles
[x,y] = meshgrid(x_0-r2:0.2:x_0+r2,y_0-r2:0.2:y_0+r2); % meshgrid of points
U = cos(x)./sqrt(x.^2+y.^2);
V = sin(x)./sqrt(x.^2+y.^2);
streamslice(x,y,U,V);

所以你得到: