简体   繁体   中英

A 3D plot in MATLAB

I have two variables which i sweep, W1 and W3 . I made a nested loop of these two variables.

for i=1:size(W1,2) 
    for j=1:size(W3,2)
         d(i,j)=someexpression(W1(i),W3(j))
    end
end

I want to do a 3D plot with W1 in the x-axis and W3 in the y-axis and d should be in the z-axis so that I have a 3D plot (or some contour plot).

EDIT: The 3d plot should actually be a surface

You can do the interpolation manually:

x = linspace(W1(1), W1(end), 100);
y = linspace(W2(1), W2(end), 100);
z = interp2(W1, W2, d, x, y);
surf(x, y, z)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM