File Exchange Pick of the Week

November 2nd, 2007

Advanced MATLAB: Surface plot of nonuniform data

Two minute video shows how to fit a surface to nonuniform data.
Real data is not always on a nice X,Y grid, but the MATLAB commands
SURF and MESH expect them to be. GRIDDATA and MESHGRID help to fix this.

Video Content

Find the files here.

PodCast here

Other videos have been gathered here:
http://blogs.mathworks.com/pick/category/video/

9 Responses to “Advanced MATLAB: Surface plot of nonuniform data”

  1. Masatoshi KASUGA replied on :

    Dear Sir:

    I am very grad to find the program of “advanced-matlab-surface-plot-of-nonuniform-data”, but I could not run it
    because of no-coincide of matrix dimension.
    Would you please inform me of a mistake I coded (copied).

    Best Regards,
    ————————

    %3D graph for nonuniform_data
    x=rand(100,1)*16-8;
    y=rand(100,1)*16-8;
    r=sqrt(x.^2+y.^2)+eps;
    z=sin(r)./r;
    %
    xlin=linspace(min(x),max(x),33);
    ylin=linspace(min(y),max(y),33);
    [X,Y]=meshgrid(xlin,ylin);
    Z=griddata(x,y,z,X,Y,’cubic’);
    %
    mesh(X,Y,Z); % interpolated
    axis tight; hold on
    plot3(x,y,z,’.',’MarkerSize’,15)
    %%surf(X,Y,Z)

  2. paul replied on :

    I copied the code from you message and it worked perfectly on my side! - sorry!

  3. Doug replied on :

    The code you pasted here worked exactly right for me too. I am not sure what to do for you.

    Sorry,
    Doug

  4. Doug replied on :

    Greg pointed me to this solution he wrote a while back that might be of interest also:

    Tech Note 1212 - Using MESHGRID and GRIDDATA to Fit Vector Data and Plot Unevenly Spaced Data http://www.mathworks.com/support/tech-notes/1200/1212.html

  5. Els replied on :

    Dear Doug,

    This info about making a surface plot was very usefull for me. In stead of the formule that you used to produce some points, I used 4 XYZ-coordinates that result in an surface in 3D. Is there an easy way to calculate the surface area of this created object?

    Best regards,
    Els

  6. Doug replied on :

    Els,

    There is no built in function to do this, but knowing the X,Y,Z of each point in the mesh, you should be able to calculate the area of each four point patch. From there, summing should be easy to know the whole area.

    Doug

  7. Jim replied on :

    I have three column data (time,height,collection) supposedly x,y,z data. I want to plot it and get the equation. How can I do that with Matlab.
    eg data:
    x - y - z
    1 - 1 - 130
    2 - 1 - 130
    3 - 1 - 130
    4 - 1 - 130
    7 - 2 - 130
    10 - 2 - 130
    16 - 2 - 130
    25 - 2 - 130
    40 - 2 - 130
    63 - 3 - 130
    100 - 3 - 130
    160 - 3 - 130
    250 - 3 - 130
    300 - 3 - 130
    400 - 3 - 130
    500 - 3 - 130
    1 - 3 - 260
    2 - 3 - 260
    3 - 3 - 260
    4 - 3 - 260
    7 - 3 - 260
    10 - 3 - 260
    16 - 4 - 260
    25 - 4 - 260
    40 - 4 - 260
    63 - 6 - 260
    100 - 8 - 260
    160 - 10 - 260
    250 - 11 - 260
    300 - 11 - 260
    400 - 11 - 260
    500 - 11 - 260
    1 - 4 - 390
    2 - 5 - 390
    3 - 5 - 390
    4 - 5 - 390
    7 - 6 - 390
    10 - 7 - 390
    16 - 8 - 390
    25 - 10 - 390
    40 - 12 - 390
    63 - 14 - 390
    100 - 15 - 390
    160 - 19 - 390
    250 - 22 - 390
    300 - 26 - 390
    400 - 30 - 390
    500 - 30 - 390
    1 - 4 - 650
    2 - 5 - 650
    3 - 5 - 650
    4 - 5 - 650
    7 - 5 - 650
    10 - 7 - 650
    16 - 8 - 650
    25 - 9 - 650
    40 - 12 - 650
    63 - 14 - 650
    100 - 18 - 650
    160 - 22 - 650
    250 - 27 - 650
    300 - 27 - 650
    400 - 36 - 650
    500 - 40 - 650
    1 - 2 - 910
    2 - 2 - 910
    3 - 2 - 910
    4 - 3 - 910
    7 - 5 - 910
    10 - 5 - 910
    16 - 7 - 910
    25 - 9 - 910
    40 - 15 - 910
    63 - 20 - 910
    100 - 24 - 910
    160 - 32 - 910
    250 - 38 - 910
    300 - 41 - 910
    400 - 46 - 910
    500 - 49 - 910

  8. venkat replied on :

    I have multiple [x,y,z] matrices of my data with which i want to plot the surface using a 7th order polynomial, how can I do that??

  9. Doug replied on :

    Venkat,

    I am not sure that I understand the question. If you have x,y,z triples, you just plot them. Are you trying to fit a polynomial to them? That would imply a two dimensional dataset. Are you trying to fit some kind of a surface to the data?

    You might be best off looking here:

    http://blogs.mathworks.com/pick/how-to-get-help/

    It shows how to ask for help at the bottom.

    Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Beats: Not useful for everyday but very interesting. Thanks.
  • nickey: Hi Brett, I’ve tested Tao’s program and yours too. They ran successfully. I’ve tried to...
  • Kika: THANK YOU!! I’ve been trying to change the colormap but I didn’t know what to do. It was driving me crazy!...
  • Richard: Hello Doug, yet another question. I followed this tutorial: http://blinkdagger.c om/matlab/matlab-...
  • Doug: Richard, Use the compiler options file, it is found at the bottom of the dialog that you get when clicking on...
  • Richard: To whom it may concern, a solution to the dos screen annoyance is found by user ‘vihang’ in this...
  • Richard: Thank you for your reply. I understand that I can specify flags using the mcc command, but is this also...
  • Doug: Richard: Find it here: http://www.mathworks .com/access/helpdesk /help/toolbox/compil er/mcc.html Doug
  • Richard: Hello Doug, Can you explain point 56. (about the -e flag) because I can’t seem to find it. Regards,...
  • Doug: Tony, When you say the .MAT file has 984 files, you mean it has the *names* of the files. So the real problem...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.