Matlab函数:rand()+delaunay()
来源:互联网 发布:uu大魔王淘宝店 编辑:程序博客网 时间:2024/06/05 20:15
转载请注明出处!!!
- rand()
功能:随机产生数的状态,
格式:
1、rand(‘state’,s)
表示随机产生数的状态state,一般情况下不用指定状态。
但是有书籍为了让读者能够看到和他书本的同样结果,采用了设置state。
示例:rand(‘state’,0)。作用在于如果指定状态,产生随机结果就相同了。
2、因为每次rand产生的随机数都不同,为了得到与之前某个状态相同的结果,用这个函数来产生该相同的随机数。
示例:
>> rand('state',0);>> x=rand(1,4);>> y=rand(1,4);>> xx = 0.9501 0.2311 0.6068 0.4860>> yy = 0.8913 0.7621 0.4565 0.0185
delaunay()
函数:delaunay()
功能:三角剖分
格式:
TRI = delaunay(x,y);
TRI = delaunay(x,y,z);
示例 :
rand('state',0);x = rand(1,4);y = rand(1,4);TRI = delaunay(x,y);triplot(TRI,x,y);%绘图TRI = 2 4 3 1 2 3 4 1 3
其中,TRI含义为:
2为右上点;
x(:,TRI(2))% ans = 0.9501>> y(:,TRI(2))ans = 0.8913
1为左上点;
x(:,TRI(1))ans = 0.2311>> y(:,TRI(1))ans = 0.7621
3为左下点
x(:,TRI(3))ans = 0.4860>> y(:,TRI(3))ans = 0.0185
4为中间点
x(:,TRI(4))ans = 0.4860>> y(:,TRI(4))ans = 0.0185
因此:
每一行的三个元素代表顶点的索引,
即,第一个三角形是由第2个、第4个、第3个顶点构成,同理后面两个三角形,
[x,y]就是四个顶点的坐标,由rand函数产生。
delaunay()
三维示例:
四面体
>> clear>> x=rand(4,3)x = 0.9218 0.9355 0.0579 0.7382 0.9169 0.3529 0.1763 0.4103 0.8132 0.4057 0.8936 0.0099>> a=x(:,1);>> b=x(:,2);>> c=x(:,3);>> tri=delaunay(a,b,c);>> trisurf(tri,a,b,c);>> trisurf(tri,a,b,c);>> [m,n]=size(tri)m = 1n = 4>> tri %点的顺序tri = 3 4 2 1>> tri(1,3)ans = 2>> tri(1,1)ans = 3>> point_1=x(3,:)%第一个点坐标point_1 = 0.1763 0.4103 0.8132>> point_2=x(tri(1,2),:) %第二个点坐标point_2 = 0.4057 0.8936 0.0099>> point_3=x(tri(1,3),:) %第三个点坐标point_3 = 0.7382 0.9169 0.3529>> point_4=x(tri(1,4),:) %第四个点坐标point_4 = 0.9218 0.9355 0.0579
例子
clc; clear; close all;rand('state',0);x = rand(1,8);y = rand(1,8);%随机数TRI = delaunay(x,y);%三角剖分triplot(TRI,x,y);%绘图figure; xmin = min(x(:)); xmax = max(x(:));ymin = min(y(:)); ymax = max(y(:));xl = xmax - xmin; yl = ymax - ymin;axis([xmin-xl*0.1, xmax+xl*0.1,... ymin-yl*0.1, ymax+yl*0.1]);%坐标轴hold on;for i = 1 : size(TRI, 1)%遍历三角形个数 t1 = TRI(i, :);%索引,三角形个数分别由哪三个点构成 for j = 1 : length(t1)-1 xt = [x(t1(j)) x(t1(j+1))]; yt = [y(t1(j)) y(t1(j+1))]; plot(xt, yt, 'k-', 'LineWidth', 2); pause(0.1); end xt = [x(t1(end)) x(t1(1))]; yt = [y(t1(end)) y(t1(1))]; plot(xt, yt, 'k-', 'LineWidth', 2); pause(0.1);end
0 0
- Matlab函数:rand()+delaunay()
- MATLAB delaunay函数使用
- MATLAB随机函数rand
- matlab rand 函数
- matlab rand函数详解
- matlab中的rand函数
- matlab中的rand函数
- matlab rand函数
- matlab随机函数rand()使用
- Matlab之rand函数的使用
- matlab函数rand,randn,randi用法整理
- Matlab编辑Delaunay Triangulations
- matlab rand
- Matlab中随机函数:rand函数,randn函数,randi函数
- matlab的rand()函数产生均匀分布函数的正确用法
- matlab2c使用c++实现matlab函数系列教程-rand函数
- matlab随机函数rand使用中应注意的问题
- rand, randn和randint函数的区别(MATLAB)
- Git Bash for Windows
- 你应该知道的 RPC 原理
- PIC单片机实现x ms/1s钟精确延时
- 开发中的缓存设计
- WebSlides
- Matlab函数:rand()+delaunay()
- 文章标题
- UVA 540 队列与映射的综合应用
- Android百分比布局
- Android自定义标签列表控件LabelsView解析
- PIC单片机实现双字节无符号数加减法
- Web项目开发流程 PC端
- php
- 深入理解卷积神经网络