m0_62128284 2023-08-14 17:45 采纳率: 75%
浏览 7
已结题

matlab怎么将指定的三维坐标点连接起来

img

img


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

  • 写回答

2条回答 默认 最新

  • 配电网和matlab 2023-08-15 15:17
    关注

    可以下载一下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
    
    
    

    运行结果:

    img

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月27日
  • 已采纳回答 8月19日
  • 创建了问题 8月14日

悬赏问题

  • ¥15 大二软件工程基础大题
  • ¥200 使用python编写程序,采用socket方式获取网页实时刷新的数据,能定时print()出来就行。
  • ¥15 matlab如何根据图片中的公式绘制e和v的曲线图
  • ¥15 我想用Python(Django)+Vue搭建一个用户登录界面,但是在运行npm run serve时报错了如何解决?
  • ¥15 QQ邮箱过期怎么恢复?
  • ¥15 登录他人的vue项目显示服务器错误
  • ¥15 (标签-android|关键词-app)
  • ¥60 如何批量获取json的url
  • ¥15 comsol仿真压阻传感器
  • ¥15 Python线性规划函数optimize.linprog求解为整数