matlab 绘图

1.三维绘图

Matlab 复制代码
% 原始数据(按行输入:x y z)
data = [
    1   2    3 ;
    5  56  234 ;
    32 34   67 
    1 2 5
];

% 提取坐标并生成网格(适用于surf函数的网格格式)
x = data(:,1);  % X坐标(行数对应Y轴)
y = data(:,2);  % Y坐标(行数对应Y轴)
z = data(:,3);  % Z值(需转换为矩阵形式)

% 转换为网格数据(假设X和Y为离散点,生成3x1网格)
[X, Y] = meshgrid(x, y);  % 生成2D网格坐标
Z = reshape(repmat(z,size(X,1),1),size(X,1),size(X,1));%3行1列;  % 重塑Z为3x3矩阵

% 创建3D曲面图
figure('Color', 'white', 'Position', [100 100 600 500])
surf(X, Y, Z, 'EdgeColor', 'none')  % 隐藏网格线
hold on

contour3(Z)
% 数据点标注(显示原始数据值)
for i = 1:3
    for j = 1:3
        text(X(i,j), Y(i,j), Z(i,j)+5, num2str(Z(i,j)), ...
             'HorizontalAlignment', 'center', 'FontSize', 10)
    end
end

% 图形美化
view(30, 20)  % 调整视角
colorbar('Location', 'eastoutside', 'Ticks', unique(Z(:)))  % 颜色条
xlabel('X 坐标', 'FontSize', 12)
ylabel('Y 坐标', 'FontSize', 12)
zlabel('Z 高度', 'FontSize', 12)
title('三维曲面图(含数据标注)', 'FontSize', 14, 'FontWeight', 'bold')
grid on  % 显示网格
lighting gouraud  % 平滑光照
colormap(parula)  % 颜色映射(更适合数据可视化)

% 数据验证(确保格式正确)
disp('原始数据矩阵:'); disp(data)
disp('转换后的网格尺寸:'); disp(size(Z))
相关推荐
等等54310 分钟前
Java EE初阶——wait 和 notify
java·开发语言
低代码布道师18 分钟前
第五部分:第一节 - Node.js 简介与环境:让 JavaScript 走进厨房
开发语言·javascript·node.js
盛夏绽放35 分钟前
Python字符串常用方法详解
开发语言·python·c#
好吃的肘子2 小时前
Elasticsearch架构原理
开发语言·算法·elasticsearch·架构·jenkins
nlog3n2 小时前
Go语言交替打印问题及多种实现方法
开发语言·算法·golang
kaixin_learn_qt_ing2 小时前
Golang
开发语言·后端·golang
ddd...e_bug2 小时前
Shell和Bash介绍
开发语言·bash
C4程序员3 小时前
Java百度身份证识别接口实现【配置即用】
java·开发语言
unityのkiven3 小时前
C++中的虚表和虚表指针的原理和示例
开发语言·c++
炒空心菜菜3 小时前
MapReduce 实现 WordCount
java·开发语言·ide·后端·spark·eclipse·mapreduce