Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Triangulation 3d plot

Subject: Triangulation 3d plot

From: Frédéric Bergeron

Date: 12 Jul, 2010 19:09:04

Message: 1 of 4

Hi,

I want have a set of x,y and z data. I want to produce a 3d surf plot that looks like this from the x-y view: http://pics.imagup.com/ano1/1279019256.jpg .

I tried to use trisurf, combined with delaunay and meshgrid functions, but the boundaries of my data are not connecting with long distance points, as it does in the image from the hyperlink. I want clean boundaries lines, that will look like a turned rectangle, using my sample code below. Is there a way to do it?? Here's is my sample test code so far:

%Test data
x=1:20;
y=1:20;
[xgrid,ygrid]=meshgrid(x,y);
zgrid=xgrid+.5*ygrid+2*rand(20,20);

%Some NaN in my reel data
zgrid(ygrid>xgrid+5)=NaN;zgrid(ygrid<xgrid-5)=NaN;
zgrid(ygrid<-xgrid+4)=NaN;zgrid(ygrid>-xgrid+32)=NaN;

%Triangulation
tri=delaunay(xgrid,ygrid);
handles.graph_champ_reel=trisurf(tri,xgrid,ygrid,zgrid);
%Not connecting data with lines longuer than sqrt(2)...
%that the image from the hyperlink does...

Thank you very much. Best regards,
Fred

Subject: Triangulation 3d plot

From: Frédéric Bergeron

Date: 12 Jul, 2010 20:24:04

Message: 2 of 4

Hey,
Just to say I have found my mistake, so I don't need help for that anymore. It was related to the presence of NaN values in some of the matrixes, but not in all of them. If anyone's interested, here's the code that works the way I wanted:

    %Test data
    x=1:20;
    y=1:20;
    [xgrid,ygrid]=meshgrid(x,y);
    zgrid=xgrid+.5*ygrid+2*rand(20,20);

    %Some NaN in my reel data: indexing,
    %THEN putting the NaNs in every matrix
    idx1=ygrid>xgrid+5;
    idx2=ygrid<xgrid-5;
    idx3=ygrid<-xgrid+4;
    idx4=ygrid>-xgrid+32;
    
    xgrid(idx1)=NaN;xgrid(idx2)=NaN;
    xgrid(idx3)=NaN;xgrid(idx4)=NaN;
    
    ygrid(idx1)=NaN;ygrid(idx2)=NaN;
    ygrid(idx3)=NaN;ygrid(idx4)=NaN;
    
    zgrid(idx1)=NaN;zgrid(idx2)=NaN;
    zgrid(idx3)=NaN;zgrid(idx4)=NaN;
    
    %Triangulation WITHOUT the NaNs
    tri=Delaunay(xgrid(~isnan(xgrid)),ygrid(~isnan(ygrid)));
    trisurf(tri,xgrid(~isnan(xgrid)),ygrid(~isnan(xgrid)),zgrid(~isnan(xgrid)));

Subject: Triangulation 3d plot

From: Christopher Rouxel

Date: 13 Jul, 2010 02:57:04

Message: 3 of 4

Frédéric,
I just uploaded this GUI that should help you do this quickly.
http://www.mathworks.com/matlabcentral/fileexchange/28177-3d-performance-map-gui
good luck,
Christopher

Subject: Triangulation 3d plot

From: Christopher Rouxel

Date: 13 Jul, 2010 02:57:04

Message: 4 of 4

Frédéric,
I just uploaded this GUI that should help you do this quickly.
http://www.mathworks.com/matlabcentral/fileexchange/28177-3d-performance-map-gui
good luck,
Christopher

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us