X和Y是1 * 50000的矩阵,我已经使用了图(X,Y)。
Z是距离,它是1 * 30矩阵,它表示不同长度的不同x,y数据,Z与F(x,y)无关。
例如,在Z = 1时,存在X,Y的图 在Z = 1.7时,还有另一对X,Y等
所以我怎么能告诉matlab要做的,因为在plot3中Z是F(x,y)的函数
谢谢!
答案 0 :(得分:2)
如果我正确理解了您的问题,您可以使用meshgrid
生成所需的数据。请参阅下面的简单示例:
X = [1 2 3 4 5];
Y = [3 2 1 9 5];
Z = [1 1.5 2];
[x,z] = meshgrid(X,Z);
[y,~] = meshgrid(Y,Z);
plot3(x',y','z')
答案 1 :(得分:1)
如果你想为Z的每个元素绘制一组点(X,Y),这非常简单。您只需复制(X,Y)
中每个点的Z元素Z = 1:30;
figure;
hold on;
% I'm only plotting the first two elements of Z for simplicity
% Change the length of the for loop to plot them all
for ii=1:2
% I randomly initialize (X,Y) for demonstration purposes,
% but you would probably load them from somewhere else.
X = rand(1 ,500);
Y = rand(1, 500);
scatter3(X, Y, reshape(repmat(Z(ii), 500, 1), 1, []));
% You could also use plot3
% Rotate the resulting figure to see both layers
end
如果您还可以连接(X,Y)集以提高效率,
% In your code, X1, X2, and Y1, Y2 should correspond to the (X,Y) pairs
% for the first two elements of Z
X = [X1; X2];
Y = [Y1; Y2];
Z = 1:2;
scatter3(X(:), Y(:), reshape(repmat(Z, 1, 500), 1000, []));