Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 在MATLAB中以功能区的形式绘制2D向量在图上的演变

我想绘制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{:});

更多&回答...
poster 当前离线   回复时引用此帖
 

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 05:17


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.