Plot Surface when Z is not a function of X and Y
Ältere Kommentare anzeigen
Hi everyone.
I am trying to plot my data in 3D surface. However, it currently does not work since my X,Y, and Z are independent. Z is not F(X,Y). I also try to use meshgrid but still does not work. The reason that I want to plot surface because my scatter plot points are trade-off. Thus, if i can show it in surface, it will be easier to interpolate my trade-off. Do I have any other ways to use surf function?
Thank you very much.
Antworten (1)
Image Analyst
am 17 Jan. 2015
0 Stimmen
What relationship is there between z and x and y? What is z? Is it a 2D matrix? Is it a vector? Is it a volumetric array, like a CT or MRI image?
11 Kommentare
OoM
am 17 Jan. 2015
Image Analyst
am 17 Jan. 2015
Why not just do
surf(Z);
Attach any visualizations you can to help us understand what you want or what you are getting.
OoM
am 17 Jan. 2015
Meva
am 25 Aug. 2016
I have a question related to this. My Z function depends on X, Y but not directly. So I plot my Z function using surf(Z). The problem is x, and y axes are wrong and I cannot change them. They supposed to be between 0 and 1 but they are between 0 and 100
Steven Lord
am 25 Aug. 2016
surf(Z) creates a three-dimensional shaded surface from the z
components in matrix Z, using x = 1:n and y = 1:m, where
[m,n] = size(Z).
You want to use this syntax for surf:
surf(X,Y,Z) uses Z for the color data and surface height.
X and Y are vectors or matrices defining the x and y components
of a surface.
X, Y, and Z don't need to be related, but if you specify all three they must be compatibly sized as described in the documentation. For example, this is a valid call to surf where Z is completely random and so is not a function of either X or Y.
>> x = 1:10:100;
>> y = x.^2;
>> z = randn(10);
>> surf(x, y, z)
Meva
am 25 Aug. 2016
When I tried yours, yes it works. When I tried mine, it does not.
Error is the following :
Data dimensions must agree. surf(t,x,u1array)
My u1array : 201*101 sized array.
t = 0:0.01:2;
x = 0: 0.01:1;
If I type,
t = 0:dt:2;
x=0:dx:1;
surf(t,x,u1array)
it gives above error.
If I type,
surf(u1array)
it gives a surface plot but x and y axes are not what I want . The x and y axes should be in t and x range.
Steven Lord
am 25 Aug. 2016
Another quote from the documentation page:
If X and Y are vectors, length(X) = n and length(Y) = m,
where [m,n] = size(Z).
Since u1array is of size [201, 101] we have m = 201 and n = 101. The length of your X vector must be 101 and the length of your Y vector must be 201. As written, they aren't. To correct this, inside your surf call either swap the positions of t and x (use x as the first input and t the second) or transpose u1array.
Meva
am 25 Aug. 2016
The weird thing is this point actually. I tried this before posting my previous comment. However,
surf(x,t,u1array)
does not work as well.
Meva
am 26 Aug. 2016
I just want to know whether Matlab can do this or not,
Torsten
am 26 Aug. 2016
t=0:0.01:2;
x=0:0.01:1;
surf(x,t,u1array);
does not work for u1array being 201x101 ?
That's surprising.
Best wishes
Torsten.
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
