How to create a 3D surface, then plot peaks at specific points on the 3D surface?

I want to plot a 3D surface that is 0 to 4 on the x-axis, 0 to 1 on y-axis and 0 on the z-axis (or some z if necessary like 0 to 1). Then I want to plot peaks on that surface, given the x, y, and z coordinates of the peak on the surface.
The data looks similar to:
if true
% Data (not code)
x y z
0.75 0.23 -2.86
0.75 0.47 3.87
0.75 0.64 2.78
2.45 0.23 4.56
2.45 0.47 0.89
2.45 0.64 2.74
3.23 0.23 2.10
3.23 0.47 -3.65
3.23 0.64 -5.89
Each row of the data is the x, y, and z coordinate of a specific peak on the 4 by 1 (0 to 4 on the x-axis, 0 to 1 on y-axis and 0 on the z-axis) surface.
The code that I am using now (written by Stephen Cobeldick ):
if true
close all
a=[0.75 0.23 -2.86
0.75 0.47 3.87
0.75 0.64 2.78
2.45 0.23 4.56
2.45 0.47 0.89
2.45 0.64 2.74
3.23 0.23 2.10
3.23 0.47 -3.65
3.23 0.64 -5.89]
x = reshape(a(:,1),3,3);
y = reshape(a(:,2),3,3);
z = reshape(a(:,3),3,3);
surf(x,y,z, 'FaceColor','interp')
end
This results in this:
This code sort of works in the sense that it shows the distortion of the data a crossed a surface, but it would be ideal to create a 4 by 1 (0 to 4 on the x-axis, 0 to 1 on y-axis and 0 on the z-axis) surface and then create specific peaks on that surface.
The end result that I am looking for is something that resembles this:
I would really appreciate any code that would help me to accomplish this goal.
Thank you

3 Comments

Yeah I wrote that post. I re-posted this question with more clarification. The answer given on that post was not exactly what I was looking for.
So what do we do with the other post? Are you planning to mark the existing response there as Accepted?

Sign in to comment.

 Accepted Answer

I can’t get peaks from your data. This is the best possible without more data:
d = [0.75 0.23 -2.86
0.75 0.47 3.87
0.75 0.64 2.78
2.45 0.23 4.56
2.45 0.47 0.89
2.45 0.64 2.74
3.23 0.23 2.10
3.23 0.47 -3.65
3.23 0.64 -5.89]; % x = d(:,1), y = d(:,2), z = d(:,3)
xg = linspace(min(d(:,1)), max(d(:,1)), 25);
yg = linspace(min(d(:,2)), max(d(:,2)), 25);
[X,Y] = meshgrid(xg, yg);
F = scatteredInterpolant(d(:,1), d(:,2), d(:,3));
Z = F(X, Y);
figure(1)
meshc(X, Y, Z)
hold on
scatter3(d(:,1), d(:,2), d(:,3), 'Filled')
hold off
grid on
view([35 35])
and produces this plot:

4 Comments

I really appreciate the help. That is kind of what I am looking to do. However I wondering is there a way to have a flat plane surface and at a specific point the plane distorts up or down at that specific point. I understand that there are infinite number of lines that can go through a point, but I was wondering if it was possible to make a specific peak on a flat plane with just a data point? Like is there an algorithm that can automatically draw lines from the flat plane to the peak point.
My pleasure.
You don’t have any peaks. You don’t have enough data to define anything other than what scatteredInterpolant produced.
You could certainly develop a mathematical model of the process that produced your data, then fit it to your data to it (estimate its parameters) and produce peaks that way (that is, if your model produces peaks), but your data themselves don’t produce them.
I would get more data if possible, then (in the absence of a model), use scatteredInterpolant or another interpolation function to see if you can create a more descriptive surface.
if true
% Code from another forum not sure the author
a=[0.75 0.23 -2.86
0.75 0.47 3.87
0.75 0.64 2.78
2.45 0.23 4.56
2.45 0.47 0.89
2.45 0.64 2.74
3.23 0.23 2.10
3.23 0.47 -3.65
3.23 0.64 -5.89
0 0 0
4 0 0
4 1 0
0 1 0]
figure1 = figure;
x= a(:,1);
y=a(:,2);
z=a(:,3);
dx=0.05;
dy=0.05;
x_edge=[floor(min(x)):dx:ceil(max(x))];
y_edge=[floor(min(y)):dy:ceil(max(y))];
[X,Y]=meshgrid(x_edge,y_edge);
Z=griddata(x,y,z,X,Y);
surf(X,Y,Z)
I just added the corners of the flat surface as four additional points and it created a base line for the data to correlate to creating peaks at the points of the data. Thank you for all the help.

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!