Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

matlab - Generate a 3D surface plot by fitting over many 2D plots with varying z value

I would like to achieve a 3D surface plot. My outputs are as follows.

For a particular value of z, I get y for each value of x (x ranges like 0:0.1:1.4).

Then I vary z and, for the same range of x, I get y values.

The result can be visualised as 2D plots at discrete z values, consisting of the range of x and its corresponding y. Here is my original plot:

plot

I would like to create a 3D surface plot instead, like a blanket wrapped over the above 2D plots.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's an example for the two types of plots:

figure
hold on
grid on
view(30,40)
x = 0:.01:4;
z = .3:.3:3;
y = NaN(numel(x), numel(z));
for k = 1:numel(z)
    y(:,k) = abs((4-x).*sin(x/(1+z(k)))); % compute a vector as function output
        % for input vector x, for each z. Store as a column in matrix y
    plot3(x,repmat(z(k),size(x)),y(:,k)) % plot in 3D space
end

figure
surf(x,z,y.','edgecolor','none') % surface plot
view(30,40)
grid on

enter image description here

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...