Add surface based on two vectors in 3D plot

1 次查看(过去 30 天)
In the code below, my aim is to mark the span spanned by the vectors x1 and x2. So I need to add a 2D surface in the 3D plot indicting this span which needs to visually contain the two vectors - so that I can give a sense of what a span is to the students. I tried this with the mesh function but apparently something is wrong. Is my approach wrong? How can I draw this surface?
t = [0 0 0]';
x1 = [1 2 1]';
x2 = [3 1 1]';
y = [3 3 4]';
X = [x1 x2];
B_hat = inv(X'*X)*X'*y;
plot3([t(1) x1(1)],[t(2) x1(2)],[t(3) x1(3)])
hold on
plot3([t(1) x2(1)],[t(2) x2(2)],[t(3) x2(3)])
axis([-1 5 -1 5 -1 5])
grid on
hold on
x1_fit = min(x1):1:max(x1);
x2_fit = min(x2):1:max(x2);
[x1_FIT,x2_FIT] = meshgrid(x1_fit,x2_fit);
y_FIT = B_hat(1)*x1_FIT + B_hat(2)*x2_FIT;
mesh(x1_FIT,x2_FIT,y_FIT)

采纳的回答

jonas
jonas 2018-10-6
编辑:jonas 2018-10-6
It's not trivial to make a triangular surface from three points in space, at least not from the mesh function. I would probably just use a patch.
patch('xdata',[t(1) x1(1) x2(1)],'ydata',[t(2) x1(2) x2(2)],'zdata',[t(3) x1(3) x2(3)])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by