Matlab的网格函数和流水线函数不匹配。如何修复?
%% direction field plot
[x,y]=meshgrid(-4:.5:4,-4:.5:4);
dx = 2*x +1*y;
dy = 1*x +2*y;
dxu = dx./sqrt(dx.^2+dy.^2);
dyu = dy./sqrt(dx.^2+dy.^2);
quiver(x,y,dxu,dyu)
hold on
%% Trajectory Plot
startx = repmat([-4:.5:4], 0,2);
starty = ones(size(startx));
streamline(x,y,dxu, dyu, startx, starty)
dxu = dx./sqrt(dx.^2+dy.^2);
dyu = dy./sqrt(dx.^2+dy.^2);
print('c:\data\DirectionField','-dmeta')
saveas(gcf, 'c:\data\streamline.emf')
hold off
错误消息如下:
Error using repmat!
Replication factors must be a row vector of integers or integer scalars.
当我在代码中添加了7个轨迹图时,就发生了这种情况。当只使用两个轨迹时,错误没有发生吗?这是怎么回事?
MM
发布于 2018-12-10 13:20:19
您的startx
和starty
矩阵当前为空。repmat
的最后两个参数应该是您希望分别在垂直和水平方向上重复矩阵的次数。由于您的复制因子是0
和2
,因此结果是一个空矩阵。使用正整数作为复制因子。
我不完全确定您想要做什么,但是如果您希望quiver
和streamline
图保持一致,我认为您根本不应该使用repmat
。相反,我认为你应该这样做:
streamline(x, y, dxu, dyu, x, y);
在OP的评论之后更新了:
如果想要从一组特定的起点绘制轨迹,请使用下面的代码,其中startxy
是一个包含m
起点坐标的m x 2
矩阵。
startxy = [0,2;
1,-3;
2,1]; %e.g. 3 starting points
streamline(x,y,dxu, dyu, startxy(:,1), startxy(:,2));
https://stackoverflow.com/questions/53698683
复制相似问题