Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab不规则形状曲面图_Matlab_Matlab Figure - Fatal编程技术网

Matlab不规则形状曲面图

Matlab不规则形状曲面图,matlab,matlab-figure,Matlab,Matlab Figure,我打算用Matlab绘制随机过程在其状态空间上的概率分布。状态空间可以用150x150矩阵的下三角表示。关于某一时间点的概率分布,请参见图(无网格的冲浪图) 正如我们所看到的,图中有高度的对称性,但因为它是以正方形矩阵绘制的,所以看起来有点奇怪。如果我们可以变换矩形,绘图就会看起来很完美。我的问题是,如何使用Matlab将下部三角形部分绘制/转换为等边三角形?此函数应该可以为您完成这项工作。如果没有,请告诉我 function matrix_lower_tri_to_surf(A) %Disp

我打算用Matlab绘制随机过程在其状态空间上的概率分布。状态空间可以用150x150矩阵的下三角表示。关于某一时间点的概率分布,请参见图(无网格的冲浪图)


正如我们所看到的,图中有高度的对称性,但因为它是以正方形矩阵绘制的,所以看起来有点奇怪。如果我们可以变换矩形,绘图就会看起来很完美。我的问题是,如何使用Matlab将下部三角形部分绘制/转换为等边三角形?

此函数应该可以为您完成这项工作。如果没有,请告诉我

function matrix_lower_tri_to_surf(A)
%Displays lower triangle portion of matrix as an equilateral triangle
%Martin Stålberg, Uppsala University, 2013-07-12
%mast4461 at gmail

siz = size(A);
N = siz(1);
if ~(ndims(A)==2) || ~(N == siz(2))
    error('Matrix must be square');
end

zeds = @(N) zeros(N*(N+1)/2,1); %for initializing coordinate vectors
x = zeds(N); %x coordinates
y = zeds(N); %y coordinates
z = zeds(N); %z coordinates, will remain zero
r = zeds(N); %row indices
c = zeds(N); %column indices

l = 0; %base index
xt = 1:N; %temporary x coordinates
yt = 1; %temporary y coordinates

for k = N:-1:1
    ind = (1:k)+l; %coordinate indices
    l = l+k; %update base index

    x(ind) = xt; %save temporary x coordinates

    %next temporary x coordinates are the k-1 middle pairwise averages
    %calculated by linear interpolation through convolution
    xt = conv(xt,[.5,.5]);
    xt = xt(2:end-1);

    y(ind) = yt; %save temporary y coordinates
    yt = yt+1; %update temporary y coordinates

    r(ind) = N-k+1; %save row indices
    c(ind) = 1:k; % save column indices
end

v = A(sub2ind(size(A),r,c)); %extract values from matrix A
tri = delaunay(x,y); %create triangular mesh

h = trisurf(tri,x,y,z,v,'edgecolor','none','facecolor','interp'); %plot surface
axis vis3d; view(2); %adjust axes projection and proportions
daspect([sqrt(3)*.5,1,1]); %adjust aspect ratio to display equilateral triangle

end %end of function

这个函数应该为您完成这项工作。如果没有,请告诉我

function matrix_lower_tri_to_surf(A)
%Displays lower triangle portion of matrix as an equilateral triangle
%Martin Stålberg, Uppsala University, 2013-07-12
%mast4461 at gmail

siz = size(A);
N = siz(1);
if ~(ndims(A)==2) || ~(N == siz(2))
    error('Matrix must be square');
end

zeds = @(N) zeros(N*(N+1)/2,1); %for initializing coordinate vectors
x = zeds(N); %x coordinates
y = zeds(N); %y coordinates
z = zeds(N); %z coordinates, will remain zero
r = zeds(N); %row indices
c = zeds(N); %column indices

l = 0; %base index
xt = 1:N; %temporary x coordinates
yt = 1; %temporary y coordinates

for k = N:-1:1
    ind = (1:k)+l; %coordinate indices
    l = l+k; %update base index

    x(ind) = xt; %save temporary x coordinates

    %next temporary x coordinates are the k-1 middle pairwise averages
    %calculated by linear interpolation through convolution
    xt = conv(xt,[.5,.5]);
    xt = xt(2:end-1);

    y(ind) = yt; %save temporary y coordinates
    yt = yt+1; %update temporary y coordinates

    r(ind) = N-k+1; %save row indices
    c(ind) = 1:k; % save column indices
end

v = A(sub2ind(size(A),r,c)); %extract values from matrix A
tri = delaunay(x,y); %create triangular mesh

h = trisurf(tri,x,y,z,v,'edgecolor','none','facecolor','interp'); %plot surface
axis vis3d; view(2); %adjust axes projection and proportions
daspect([sqrt(3)*.5,1,1]); %adjust aspect ratio to display equilateral triangle

end %end of function

矩形的下三角形永远不会等边。您应该能够将绘图中的
90°
角度更改为
60°
。也许这个软件会有用@freude,这个软件看起来确实有用。我来看看。@JackOLantern,事实上反对角线的细胞数和三角形的其他两边一样多,这就是为什么它可以等边。看看这里:矩形的下三角形永远不会等边。您应该能够将绘图中的
90°
角度更改为
60°
。也许这个软件会有用@freude,这个软件看起来确实有用。我来看看。@Jackolanten,事实上反对角线的单元格数和三角形的其他两边一样多,这就是为什么它可以是等边的。看看这里:在
x=zeds(N)中似乎有一个未定义的变量
N
显然我没有正确地测试函数。编写了一些测试用例并修复了错误。如果功能符合您的要求,请考虑将我的答案标记为已接受,谢谢!在
x=zeds(N)中似乎有一个未定义的变量
N
显然我没有正确地测试函数。编写了一些测试用例并修复了错误。如果功能符合您的要求,请考虑将我的答案标记为已接受,谢谢!