How to plot a 3D surface with two vectors and one array?
Show older comments
I want to plot a 3D surface
, but I cannot apply the surf() command straightforwardly for some reason.
, but I cannot apply the surf() command straightforwardly for some reason.I have two vectors for x and y coordinates. Let us say
x = linspace(-10, 10, 100);
y = linspace(-0.5, 0.5, 100);
To calzulate
I have to call some function which works only for fixed values of x and y. Thys, I calculate it as follows
I have to call some function which works only for fixed values of x and y. Thys, I calculate it as followsfor i = 1 : length(x)
for j = 1 : length(y)
func(i,j) = @MyFunction(__some_parameters__, x(i), y(j));
end
end
As a result I have two vectors for x and y and a matrix of the size length(x)*length(y) for the variable z. Could you tell me please, if there are any convenient methods to rewrite this data to a format that is appropriate for applying the surf() command?
P.S. I used plot3(x(i), y(j), func(i,j), 'b.') with two cycles, but it is a ridiculous "dirty hack" and not a surface.
Accepted Answer
More Answers (0)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!