Choosing the Axis for Interp2?

24 views (last 30 days)
I do not understand why I cannot switch the axis that the interp2 function runs on?
As you can see with the code below I am attempting to get a cross section in the "X-Z" plane instead of the "Y-Z" as shown in the first block.
X=-1:0.1:1;
Y=-1:0.1:1;
Z=membrane(1,10,10);
figure(1)
surf(X,Y,Z);
x=-0.5;
z=interp2(X,Y,Z,x,Y);
figure(2)
plot(Y,z);
y=-0.5;
z1=interp2(X,Y,Z,y,X);
figure(3)
plot(X,z1)

Accepted Answer

Star Strider
Star Strider on 26 May 2022
Use plot3 instread of plot, since the plot is in three dimensions —
X=-1:0.1:1;
Y=-1:0.1:1;
Z=membrane(1,10,10);
figure(1)
surf(X,Y,Z);
xlabel('X')
ylabel('Y')
x=-0.5;
z=interp2(X,Y,Z,x,Y);
figure(2)
surf(X,Y,Z)
hold on
plot3(ones(size(X))*x,Y,z, '-r', 'LineWidth',3);
hold off
xlabel('X')
ylabel('Y')
y=-0.5;
z1=interp2(X,Y,Z,X,y);
figure(3)
surf(X,Y,Z)
hold on
plot3(X,ones(size(Y))*y,z1, '-r', 'LineWidth',3);
hold off
grid on
xlabel('X')
ylabel('Y')
.

More Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!