I have a surface and I want to plot peaks on the 3D surface in matlab
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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:
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 surface.
The code that I am using now (written by Stephen):
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')
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 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
1 Commento
Stephen23
il 8 Giu 2015
Modificato: Stephen23
il 8 Giu 2015
This is not the code that you have been using, because the vector a does not contain any ;-characters to indicate a new line of the array. And it seems that x, y and z are supposed to be the (presumably multiple) values over all rows of a, yet each of which are scalars and generate an error when the code is run:
Error using surf (line 75)
Data dimensions must agree.
Error in temp (line 11)
surf(X,Y,Z)
Please edit the question to give your actual code (not an edited version), and format the code correctly for this forum by using the {} Code button that you will find above the textbox.
Risposta accettata
Più risposte (1)
Stephen23
il 8 Giu 2015
Modificato: Stephen23
il 8 Giu 2015
That data is actually arranged in sets of three, like it was in a matrix that was then flattened out. So if we convert it back into a matrix then we can use surf directly using just that data (EDIT to suit OP's correctly-formatted code):
x = reshape(a(:,1),3,3);
y = reshape(a(:,2),3,3);
z = reshape(a(:,3),3,3);
surf(x,y,z, 'FaceColor','interp')
Which generates this:

2 Commenti
Stephen23
il 8 Giu 2015
Modificato: Stephen23
il 9 Giu 2015
How exactly should it resemble this? Do you want to interpolate the data with some curves? Is it the curve shapes that you are trying to generate? Do you realize that there are an infinite number of curves that fit through those points, even if they are specified as peaks on a surface... simply specifying some peaks is not adequate information to uniquely define a curve, unless you know or choose some other attributes of that curve.
Therefore you might like to read about splines and 2D curve-fitting:
and also thin-plate smoothing splines:
Also note that you have edited your question and replaced the original code that you provided with exactly the code from my answer, without acknowledging this. It is considered polite on this forum to acknowledge when you have taken someone's code or idea, otherwise you make it look like your own work (this is called plagiarism). And please make a note of any edits within the text.
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
