

为什么matlab的gplot函数画出来的函数是二维的,但是这里的XY明明是三维的,有什么函数或方法可以画出三维的这样指定点连接的图形吗?


可以下载一下gplot3函数,地址如下:
https://ww2.mathworks.cn/matlabcentral/fileexchange/49762-gplot3-plotting-simple-graphs-in-3d
一个测试代码:
clc
clear
[D,XY] = bucky;
gplot3(D,XY,'-*')
axis square
function h = gplot3(A, xyz, varargin)
%GPLOT Plot graph (nodes and edges).
% GPLOT(A, xyz) plots the graph specified by the adjacency matrix,
% A, and the n-by-3 coordinate array, xyz.
%
% GPLOT(A, xyz, linespec) uses line type and color specified in the
% string LineSpec. See PLOT for possibilities.
%
% h = GPLOT(A, xyz) returns the a handle to the graph.
%
% h = GPLOT(A, xyz, 'LineWidth', 5, ...) also takes arbitrary arguments
% for line properties
% If no arguments given, then run buckminster sphere example
if nargin == 0
[A, xyz] = bucky;
end
% If only one argument given, throw error.
if nargin == 1
error('Please provide an adjacency matrix and coordinate array');
end
% Returns i and j, lists of connected nodes
[i,j] = find(A);
% Extact
X = [ xyz(i,1) xyz(j,1)]';
Y = [ xyz(i,2) xyz(j,2)]';
Z = [ xyz(i,3) xyz(j,3)]';
% Add NaN values to break between line segments
X = [X; NaN(size(i))'];
Y = [Y; NaN(size(i))'];
Z = [Z; NaN(size(i))'];
% Serialize the x and y data
X = X(:);
Y = Y(:);
Z = Z(:);
% If only two arguments, then plot as is
if nargin == 0 || nargin == 2
h = plot3(X, Y, Z);
end
% If linespec given, then use it
if nargin >= 3
if mod(nargin, 2) == 1
h = plot3(X, Y, Z, varargin{1});
start = 2;
else
h = plot3(X, Y, Z);
start = 1;
end
% Now apply the rest of the var string
if ~isempty(varargin)
for i=start:2:length(varargin)
set(h, varargin{i}, varargin{i+1});
end
end
end
end
运行结果:

码字不易,有用希望采纳一下哦