how to plot 3 different vectors without any relation, in a 3d plot
6 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I want to plot 3 vectors in a same 3D plot; (plot3 and meshgrid-surf are not working for my case).
let's say three vectors are as follows:
X=[1 2 3]
Y=[4 5 6]
Z=[11 22 33]
now Z(1) corresponds to X(1) and Y(1); and so on.
plot3 does not give my desired plot; and meshgrid is not applicable since there is no simple function between Z and X,Y.
for j=0:60
for i=0:60/j
R=[i, j, optmizie(fcn)]; %this one fetchs a lot of other functions so that's why I cannot use meshgrid
end
end
I want to have i and j as X and Y axises and R az the Z axis without specifying the relation among them.
Thanks in advance
0 个评论
采纳的回答
Star Strider
2022-7-8
I am not certain what you want, so my best guess —
X=[1 2 3];
Y=[4 5 6];
Z=[11 22 33];
xv = linspace(min(X), max(X), 5);
yv = linspace(min(Y), max(Y), 5);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(X,Y,Z,Xm,Ym);
figure
surf(Xm, Ym, Zm)
grid on
This is not working with the provided data, however since this may be a ‘proxy problem’, it will likely work with your actual data.
.
2 个评论
Star Strider
2022-7-8
If you do not want to plot a surface, this is straightforward —
X=[1 2 3];
Y=[4 5 6];
Z=[11 22 33];
cm = colormap(turbo(numel(Z)));
[~,C] = sort(Z);
figure
stem3(X, Y, Z, 'Marker','none')
hold on
scatter3(X, Y, Z, 75, cm(C,:), 'filled')
plot3(X, Y, Z)
hold off
grid on
xlabel('Velocity')
ylabel('Acceleration')
zlabel('Fuel Cost Function')
I chose stem3 because it gives a bit more information than scatter3 (although they can be used together) and possibly with plot3 as well. I combined all of them here. My code will adapt to any number of points. Choose the appropriate colormap for your application. (The turbo colormap was introduced in R2020b.)
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!