Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我想绘制2D向量的幅度和方向如何随时间变化。为此,我想创建一个让人想起经典的E&B场图的图形,您可能会从入门的电磁学课程中忆起。
具体来说,我想将2D矢量点与功能区连接起来,以便于查看。在MATLAB中有简单的方法可以做到这一点吗? quiver3非常接近,但缺少功能区。也许某种参数化表面? 回答: 这是一种在3D空间中的任意两条线之间绘制带状图的解决方案。您可以在其上绘制箭袋并使用gnovice解决方案中的“ FaceAlpha”调整不透明度 为了使函数更清晰,我首先发布它时没有进行错误检查和调整函数大小(它们构成了函数主体的大部分,而且并不是特别有趣) function h = filledRibbon (x,y,z,u,v,w,c, varargin) %function filledRibbon (x,y,z,u,v,w,c, varargin) % %plots a ribbon spanning the area between the lines x,y,z and x+u,y+v,z+w %in the color c %varargin is passed directly to patch %returns a handle to the patch graphic created %make up a set of regions that span the space between the lines xr = [x(1:end-1); x(1:end-1) + u(1:end-1); x(2:end) + u(2:end); x(2:end)]; yr = [y(1:end-1); y(1:end-1) + v(1:end-1); y(2:end) + v(2:end); y(2:end)]; zr = [z(1:end-1); z(1:end-1) + w(1:end-1); z(2:end) + w(2:end); z(2:end)]; %plot the regions with no edges h = patch(xr,yr,zr,c, 'LineStyle','none', varargin{:}); 在您的实际代码中使用以下错误检查版本: function h = filledRibbon (x,y,z,u,v,w,c, varargin) %function filledRibbon (x,y,z,u,v,w,c, varargin) % %plots a ribbon spanning the area between the lines x,y,z and x+u,y+v,z+w %in the color c %varargin is passed directly to patch %returns a handle to the patch graphic created if ~exist('w', 'var') || isempty(w) w = 0; end if ~exist('u', 'var') || isempty(u) u = 0; end if ~exist('v', 'var') || isempty(v) v = 0; end if ~exist('c', 'var') || isempty(c) c = 'b'; end %make all vectors 1xN x = reshape(x,1,[]); y = reshape(y,1,[]); z = reshape(z,1,[]); %if any offsets are scalar, expand to a vector if all(size(u) == 1) u = repmat(u, size(x)); end if all(size(v) == 1) v = repmat(v, size(x)); end if all(size(w) == 1) w = repmat(w, size(x)); end %make up a set of regions that span the space between the lines xr = [x(1:end-1); x(1:end-1) + u(1:end-1); x(2:end) + u(2:end); x(2:end)]; yr = [y(1:end-1); y(1:end-1) + v(1:end-1); y(2:end) + v(2:end); y(2:end)]; zr = [z(1:end-1); z(1:end-1) + w(1:end-1); z(2:end) + w(2:end); z(2:end)]; %plot the regions with no edges h = patch(xr,yr,zr,c, 'LineStyle','none', varargin{:}); 更多&回答... |
![]() |
![]() |