Asked by ferdi bayram
on 17 Nov 2019 at 22:56

Hi all,

I am struggling a bit here, and hope somebody could help. I have a set of X Y and Z points and Z is not found by any function of X and Y. In other words, I have independent X Y and Z values and these values are;

X Y Z

288 2.79 7.55

318 4.64 14.28

127 2.31 8.31

132 7.16 17.27

264 2.31 4.32

200 2.60 6.74

268 3.06 15.12

I need to create a response surface plot (contour plot) from these values. I would be so glad and thankful if somebody could help with with that. I am sorry if question is not very clear. If not, I can ask in detail. In sort, I have eight X Y Z independent data and want to create a response surface.

Best Regards,

Ferdi

Answer by Akira Agata
on 18 Nov 2019 at 3:54

Accepted Answer

How about using an interpolation? The following is a simple example:

% Apply cubic interpolation

[xGrid,yGrid] = meshgrid(linspace(min(X),max(X)),linspace(min(Y),max(Y)));

zGrid = griddata(X(:),Y(:),Z(:),xGrid(:),yGrid(:),'cubic');

zGrid = reshape(zGrid,size(xGrid));

% Visualize the result

figure

contour(xGrid,yGrid,zGrid,'ShowText','on')

hold on

scatter(X,Y,'ro')

grid on

colorbar

ferdi bayram
on 18 Nov 2019 at 6:59

Hi Akira, It looks really nice and fancy but since I am not good at matlab that much, could you please write the whole code that I can use ? My data is in the question. I would be so glad If you could write that.

Best regards

Akira Agata
on 18 Nov 2019 at 7:46

Please try the following:

D = [288 2.79 7.55;

318 4.64 14.28;

127 2.31 8.31;

132 7.16 17.27;

264 2.31 4.32;

200 2.60 6.74;

268 3.06 15.12];

X = D(:,1);

Y = D(:,2);

Z = D(:,3);

% Create 100x100 grid mesh (x,y) points

[xGrid,yGrid] = meshgrid(linspace(min(X),max(X)),linspace(min(Y),max(Y)));

% Interpolation

zGrid = griddata(X(:),Y(:),Z(:),xGrid(:),yGrid(:),'cubic');

zGrid = reshape(zGrid,size(xGrid));

% Fig.1 Contour plot with original data points

figure

contour(xGrid,yGrid,zGrid,'ShowText','on')

hold on

scatter(X,Y,'ro')

grid on

colorbar

% Fig.2 Surf plot

figure

surf(xGrid,yGrid,zGrid)

colormap(jet)

colorbar

ferdi bayram
on 18 Nov 2019 at 19:28

Thank you very much Akira, it worked :)

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Shubham Gupta (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491600-how-do-i-create-a-3-dimensional-response-surface-plot-from-x-y-z-points#comment_768328

## ferdi bayram (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491600-how-do-i-create-a-3-dimensional-response-surface-plot-from-x-y-z-points#comment_768350

## ferdi bayram (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491600-how-do-i-create-a-3-dimensional-response-surface-plot-from-x-y-z-points#comment_768352

Sign in to comment.