[英]matlab plot3 if z is not a function of F(x,y)
X and Y are matrix of 1*50000, I have already use plot(X,Y). X和Y是1 * 50000的矩阵,我已经使用plot(X,Y)。
Z is the distance, it is a 1*30 matrix, it represents different x,y data at different length, and Z is independent of F(x,y). Z是距离,它是1 * 30的矩阵,它表示不同长度的不同x,y数据,并且Z与F(x,y)无关。
For example, at Z=1 there is a graph of X,Y at Z=1.7 there is another pair of X,Y, etc 例如,在Z = 1处有X,Y的图,在Z = 1.7处有另一对X,Y,依此类推
so how can I tell matlab to do is, because in plot3 Z is a function of F(x,y) 所以我该如何告诉Matlab,因为在plot3中Z是F(x,y)的函数
thanks! 谢谢!
If I understood your question correctly you can use meshgrid
to generate to required data. 如果我正确理解了您的问题,则可以使用meshgrid
生成所需的数据。 See my simple example below: 请参阅下面的简单示例:
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')
If you want to plot a set of points (X,Y) for each element of Z, this is pretty straightforward. 如果要为Z的每个元素绘制一组点(X,Y),这非常简单。 You just need to copy the element of Z for each point in (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
If you can also concatenate your (X,Y) sets for efficiency, 如果您还可以串联(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, []));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.