1
votes

I intend to use Matlab to plot the probability distribution from stochastic process on its state space. The state space can be represented by the lower triangle of a 150x150 matrix. Please see the figure (a surf plot without mesh) for a probability distribution at a certain time point.

enter image description here

As we can see, there is a high degree of symmetry in the graph, but because it is plotted as a square matrix, it looks kind of weird. It we could transform the rectangle the plot would look perfect. My question is, how can I use Matlab to plot/transform the lower triangle portion as/to an equal-lateral triangle?

1
The lower triangle of a rectangle will never be equal-lateral. You should be able to change the 90° angle in the plot to 60°.Vitality
Maybe this software will be useful mathworks.com/matlabcentral/fileexchange/7210freude
@freude, the software does look useful. I'll check it out.wdg
@JackOLantern, in fact the antidiagonal has as many cells as the other two sides of the triangle, that's why it can be equal-lateral.wdg

1 Answers

1
votes

This function should do the job for you. If not, please let me know.

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