How to create a surface plot having 3 vectors?

조회 수: 63 (최근 30일)
Din N
Din N 2023년 4월 20일
편집: John D'Errico 2023년 4월 20일
I have 3 vectors X, Y, Z and each vector is 1x200.
I need to show the relationship between them on a plot. I used "plot3" which works, but it doesn't show the relationship that well.
So, I was wondering if there is a way to create a surface plot. I tried to do:
surf(X,Y,Z) but it does not work and Matlab wants Z to be a matrix where Z depends on X and Y which is not the case in my calculations.
So, is there a way to get a surface plot with X, Y, and Z?
P.S.: I looked at other questions like this, but I am still confused how their answers can be applied to my case.
  댓글 수: 2
Matt J
Matt J 2023년 4월 20일
It is not clear in what way the line plot from plot3 is insufficient, and why a surface would be better, even if you could define one.
Mathieu NOE
Mathieu NOE 2023년 4월 20일
maybe it would be worth to share your data and make a sketch of what plot you want

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
John D'Errico 2023년 4월 20일
편집: John D'Errico 2023년 4월 20일
Without knowing what your data looks like, it is difficult to help. And we don't see any data.
For example, do you think that surf should somehow automatically know how to connect these points into a closed surface? The problem is, surf cannot understand the connectivity of a random set of data. What are the relationships between those points? Should the result be a nice smooth surface? How can it possibly know? For example, you tell us that you have 200 points. Do they fall on a simple path in 3-d? Do they fall on the surface of sphere? Do they fall on some nice simple surface, that otherwise has some functional relationship? For example, here are several examples, each of whoich would be completely different in what surf might be expected to do.
t = linspace(0,4*pi);X = t.*cos(t);Y = 2*t.*sin(t);Z = t;
plot3(X,Y,Z,'o')
box on
grid on
X = rand(200,1);Y = rand(200,1);Z = exp(X + Y) + randn(size(X));
plot3(X,Y,Z,'o')
box on
grid on
XYZ = randn(200,3);
XYZ = normalize(XYZ,2,'norm');
X = XYZ(:,1);Y = XYZ(:,2);Z = XYZ(:,3);
plot3(X,Y,Z,'o')
box on
grid on
The first set of points falls on a conical helical spiral. We could probably decide it forms a surface. Or not. How should surf know?
Then we have a simple, but noisy surface, of the form Z=exp(X+Y), but with a fair amount of noise added on. Should surf somehow be able to decipher that?
Finally, a set of points that lie on the surface of a unit sphere.
Do you want me to keep on going? I can surely cook up many different examples of "surfaces" that would confuse surf.
How should surf somehow magically be able to look at each set of points, and know what you would expect to see as a result? In fact, each of those problems should be handled completely differently. But without any kind of intelligence to guide it, surf can do nothing more than give up. It is you who needs to first decide what is the connectivity of those points, and then form it into something that surf is designed to handle. The onus is on you here, the user.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by