MATLAB Answers

How to plot a surface-like plot when the data is not regularly spaced

2 views (last 30 days)
Abhinav on 12 Dec 2017
Commented: Abhinav on 13 Dec 2017
I have 3-d data, where first two columns (x,y) are independent and the third column (z) is dependent upon first two. I want to have a surface plot of the data so that I can see what region in (x,y) space gives low values of z and what region gives high values of z. But I am not able to use a surface plot because the data is not regularly spaced as required for using 'surf'. I have attached the mat-file containing three columns for reference. Is there a good way of solving this problem?


Sign in to comment.

Accepted Answer

Michal Dobai
Michal Dobai on 12 Dec 2017
Edited: Michal Dobai on 12 Dec 2017
How about this?
[xi,yi] = meshgrid(0:0.01:10, 0:0.01:10);
zi = griddata(demodata(:,1),demodata(:,2),demodata(:,3),xi,yi);
handle = surf(xi,yi,zi, 'EdgeColor', 'none');
% I adjusted color limits for better-looking plot of your data
handle.Parent.CLim = [-100 -80];
There is the whole page about it MATLAB in documentation: Interpolating Scattered Data
Result plot:
Is this what you need?


Show 1 older comment
Les Beckham
Les Beckham on 13 Dec 2017
If you have to deal with smoothing out noise in the data, or extrapolating beyond the edges of your grid, you might want to take a look at John D'Errico's excellent File Exchange submission gridfit.

Sign in to comment.

More Answers (0)

Sign in to answer this question.