【基础教程】Matlab实现等高线图
1 内容介绍
MATLAB提供函数contour()绘制等高线图,函数contourf()绘制经过填充的等高线图,具体调用格式如下:
★ contour(z):该函数绘制矩阵z的等高线。
★ contour(x,y,z):该函数在指定坐标(x,y)下,画出矩阵 z 的等高线。
★ contour(z,n):该函数绘制n条等高线。
★ contour(x,y,z,[v v]):该函数绘制高度为 v 的等高线。
2 完整代码
close all
[X, Y, Z] = peaks(512);
figure
[~, hCont] = contour(X, Y, Z, 'LineWidth', 1.5);
contourLegend(hCont)
figure
[~, hCont] = contourf(X, Y, Z);
function [hLeg, levMat] = contourLegend(hCont, txtCont, locLeg, hOther, ...
txtOther, posOther)
% [hLeg, levMat] = contourLegend(hCont, txtCont, locLeg, hOther, txtOther, ...
% posOther)
% Adds a curve description legend to a contour plot. The default descripti