Matlab irregular shape surf-like plot -


i intend use matlab plot probability distribution stochastic process on state space. state space can represented lower triangle of 150x150 matrix. please see figure (a surf plot without mesh) probability distribution @ time point.

enter image description here

as can see, there high degree of symmetry in graph, because plotted square matrix, looks kind of weird. transform rectangle plot perfect. question is, how can use matlab plot/transform lower triangle portion as/to equal-lateral triangle?

this function should job you. if not, please let me know.

function matrix_lower_tri_to_surf(a) %displays lower triangle portion of matrix equilateral triangle %martin stålberg, uppsala university, 2013-07-12 %mast4461 @ gmail  siz = size(a); n = siz(1); if ~(ndims(a)==2) || ~(n == siz(2))     error('matrix must 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, remain 0 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  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 k-1 middle pairwise averages     %calculated 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 matrix 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 , proportions daspect([sqrt(3)*.5,1,1]); %adjust aspect ratio display equilateral triangle  end %end of function 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -