今天,再给大家带来一篇关于Matlab流线图函数相关的一个streamparticles,该函数用于Matlab绘制流粒子,一个向量场的流粒子。流粒子通常由标记表示,可以显示流线图的位置和速度。本文主要讲解关于streamparticles函数的常见用法、语法说明、在不显示流线图的情况下生成流动画等用法。
下面,我们首先给出Matlab中关于streamparticles函数的帮助文档如下:
>> help streamparticles streamparticles Display stream particles. streamparticles(VERTICES) draws stream particles of a vector field. Stream particles are usually represented by markers and can show the position and velocity of a streamline. VERTICES is a cell array of 2D or 3D vertices (as if produced by STREAM2 or STREAM3). streamparticles(VERTICES, N) uses N to determine how many stream particles are drawn. The 'ParticleAlignment' property controls how N is interpreted. If 'ParticleAlignment' is 'off' (the default) and N is greater than 1, then approximately N particles are drawn evenly spaced over the streamline vertices; if N is less than or equal to 1, N is interpreted as a fraction of the original stream vertices; for example, if N is 0.2, approximately 20% of the vertices will be used. N determines the upper bound for the number of particles drawn. Note that the actual number of particles may deviate from N by as much as a factor of 2. If 'ParticleAlignment' is 'on', N determines the number of particles on the streamline with the most vertices; the spacing on the other streamlines is set to this value. The default value is N=1. streamparticles(...,'NAME1',VALUE1,'NAME2',VALUE2,...) controls the stream particles by using named properties and specified values. Any unspecified properties have default values. Case is ignored for property names. streamparticles PROPERTIES Animate - Stream particles motion [ non-negative integer ] The number of times to animate the stream particles. The default is 0 which does not animate. Inf will animate until ctrl-c is hit. FrameRate - Animation frames per second [ non-negative integer ] The number of frames per second for the animation. Inf, the default will draw the animation as fast as possible. Note: the framerate can not speed up an animation. ParticleAlignment - Align particles with streamlines [ on | {off} ] Set this property to 'on' to force particles to be drawn at the beginning of the streamlines. This property controls how N is interpreted. Also, any line property/value pairs such as 'linestyle' or 'marker' can be used. The following is the default list of line properties set by streamparticles. These can be overridden by passing in property/value pairs. Property Value -------- ----- 'LineStyle' 'none' 'Marker' 'o' 'MarkerEdgeColor' 'none' 'MarkerFaceColor' 'red' streamparticles(H,...) uses the LINE object H to draw the stream particles. streamparticles(AX,...) plots into AX instead of GCA. This option is ignored if you specify H as well. H = streamparticles(...) returns a vector of handles to LINE objects. Example 1: load wind [sx sy sz] = meshgrid(80, 20:1:55, 5); verts = stream3(x,y,z,u,v,w,sx,sy,sz); sl = streamline(verts); iverts = interpstreamspeed(x,y,z,u,v,w,verts,.025); axis tight; view(30,30); daspect([1 1 .125]) haxes = gca; haxes.SortMethod = 'ChildOrder'; camproj perspective; box on camva(44); camlookat; camdolly(0,0,.4, 'f'); h = line; streamparticles(h, iverts, 35, 'animate', 10, ... 'ParticleAlignment', 'on'); Example 2: load wind daspect([1 1 1]); view(2) [verts averts] = streamslice(x,y,z,u,v,w,[],[],[5]); sl = streamline([verts averts]); axis tight manual off; set(sl,'LineWidth',2); set(sl,'Color','r'); set(sl,'Visible','off'); iverts = interpstreamspeed(x,y,z,u,v,w,verts,.05); haxes = gca; haxes.SortMethod = 'ChildOrder'; haxes.Position = [0 0 1 1]; zlim([4.9 5.1]); hfig = gcf; hfig.Color = 'k'; h = line; streamparticles(h, iverts, 200, ... 'animate', 100, 'framerate',40, ... 'markers', 10, 'markerf', 'y');
常见用法
streamparticles(vertices) streamparticles(vertices,n) streamparticles(...,'PropertyName',PropertyValue,...) streamparticles(ax,...) streamparticles(line_handle,...) h = streamparticles(...)
语法说明
streamparticles(vertices) 绘制一个向量场的流粒子。流粒子通常由标记表示,可以显示流线图的位置和速度。vertices 是一个二维或三维顶点元胞数组(就像由 stream2 或 stream3 生成一样)。
streamparticles(vertices,n) 使用 n 确定可以绘制多少流粒子。ParticleAlignment 属性控制如何解释 n。
- 如果 ParticleAlignment 设置为 off(默认值),并且 n 大于 1,则将在流线图顶点上等间距绘制大约 n 个粒子。如果 n 小于或等于 1,n 将解释为原始流线图顶点的一部分;例如,如果 n 是 0.2,则将使用大约 20% 的顶点。n 确定所绘制的粒子数的上限。实际粒子数与 n 的偏差最多可达 2n 倍。
- 如果 ParticleAlignment 是 on,n 确定具有最多顶点的流线上的粒子数,并按此值设置其他流线图上的间距。默认值为 n = 1。
streamparticles(…,’PropertyName’,PropertyValue,…) 使用所命名的属性和指定的值控制流粒子。任何未指定的属性都使用默认值。MATLAB® 将忽略属性名称的大小写。
streamparticles(ax,…) 将在由 ax 指定的坐标区中,而不是在当前坐标区 (gca) 中创建流粒子。选项 ax 可以位于前面的语法中的任何输入参数组合之前。
流粒子属性
Animate – 流粒子运动 [非负整数]
设置流粒子动画运动的次数。默认值为 0,表示不做动画运动。Inf 表示一直做动画运动,直至您输入 Ctrl+C 为止。
FrameRate – 动画的每秒帧数 [非负整数]
此属性指定动画的每秒帧数。默认值 Inf 表示以尽可能快的速度绘制动画。请注意,动画速度可能会受到计算机速度的限制。在这种情况下,不一定能实现 FrameRate 的值。
ParticleAlignment – 使粒子与流线图对齐 [ on | {off} ]
将此属性设置为 on 可在每个流线图的开始位置绘制粒子。此属性控制 streamparticles 如何解释参数 n(流粒子数)。
流粒子为基本线条对象。除了流粒子属性,还可以指定任何线条属性,例如 Marker。调用 streamparticles 时会设置以下线条属性。
线条属性 | streamparticles 设置值 |
---|---|
LineStyle | ‘none’ |
Marker | ‘o’ |
MarkerEdgeColor | ‘none’ |
MarkerFaceColor | ‘red’ |
您可以将属性名称和值指定为 streamparticles 的参数来覆盖上述任何属性。例如,此语句使用 RGB 值将 MarkerFaceColor 设置为中度灰:
streamparticles(vertices,'MarkerFaceColor',[.5 .5 .5])
streamparticles(line_handle,…) 使用 line_handle 确定的线条对象来绘制流粒子。
h = streamparticles(…) 返回其创建的基本线条对象的句柄向量。
在不显示流线图的情况下生成流动画
此示例使用 z = 5 平面中的流线图通过流粒子来生成沿这些线条的流动画。
load wind figure daspect([1,1,1]); view(2) [verts,averts] = streamslice(x,y,z,u,v,w,[],[],[5]); sl = streamline([verts averts]); axis tight manual off; set(sl,'Visible','off') iverts = interpstreamspeed(x,y,z,u,v,w,verts,.05); zlim([4.9,5.1]); streamparticles(iverts, 200, ... 'Animate',15,'FrameRate',40, ... 'MarkerSize',10,'MarkerFaceColor',[0 .5 0])
转载文章,原文出处:MathWorks官网,由古哥整理发布
如若转载,请注明出处:https://iymark.com/articles/1957.html