matlab实验之显示地形数据

matlab实验之显示地形数据

目录

1.程序

2.效果图如下

2.1创建轮廓图

2.2以图像查看数据

2.3使用纹理贴图


1.程序

%% Displaying Topographic Data
% This example shows several ways to represent the Earth's topography. The
% data used in this example are available from the National Geophysical
% Data Center, NOAA US Department of Commerce under data announcement
% 88-MGG-02.

% Copyright 2014 The MathWorks, Inc.

%% About the Topography Data
% The data file, |topo.mat|, contains topographic data. |topo| is the
% altitude data and |topomap1| is a colormap for the altitude.

load topo topo topomap1    % load data 
whos('topo','topomap1')

%% 1.创建轮廓图
% One way to visualize topographic data is to create a contour plot. To
% show the outline of the Earth's continents, plot points that have zero
% altitude. The first three input arguments to |contour| specify the X, Y,
% and Z values on the contour plot. The fourth argument specifies the
% contour levels to plot.

x = 0:359;                                % longitude
y = -89:90;                               % latitude

figure();
contour(x,y,topo,[0 0])

axis equal                                % set axis units to be the same size
box on                                    % display bounding box

ax = gca;                                 % get current axis               
ax.XLim = [0 360];                        % set x limits
ax.YLim = [-90 90];                       % set y limits
ax.XTick = [0 60 120 180 240 300 360];    % define x ticks
ax.YTick = [-90 -60 -30 0 30 60 90];      % define y ticks

%% 2.以图像查看数据
% You can create an image of the topography using the elevation data and a
% custom colormap. The topography data is treated as an index into the
% custom colormap. Set the |CDataMapping| of the image to |'scaled'| to
% linearly scale the data values to the range of the colormap. In this
% colormap, the shades of green show the altitude data, and the shades of
% blue represent depth below sea level.
figure();
image([0 360],[-90 90], flip(topo), 'CDataMapping', 'scaled')
colormap(topomap1)

axis equal                                % set axis units to be the same size

ax = gca;                                 % get current axis               
ax.XLim = [0 360];                        % set x limits
ax.YLim = [-90 90];                       % set y limits
ax.XTick = [0 60 120 180 240 300 360];    % define x ticks
ax.YTick = [-90 -60 -30 0 30 60 90];      % define y ticks

%% 3.Use Texture Mapping
% Texture mapping maps a 2-D image onto a 3-D surface.  To map the
% topography to a spherical surface, set the color of the surface,
% specified by the |CData| property, to the topographic data and set the
% |FaceColor| property to |'texturemap'|.

figure();
[x,y,z] = sphere(50);          % create a sphere 
s = surface(x,y,z);            % plot spherical surface

s.CData = topo;                % set color data to topographic data
s.FaceColor = 'texturemap';    % use texture mapping
s.EdgeColor = 'none';          % remove edges
s.FaceLighting = 'gouraud';    % preferred lighting for curved surfaces
s.SpecularStrength = 0.4;      % change the strength of the reflected light

light('Position',[-1 0 1])     % add a light

axis square off                % set axis to square and remove axis
view([-30,30])                 % set the viewing angle

2.效果图如下

2.1创建轮廓图

matlab实验之显示地形数据_第1张图片

2.2以图像查看数据

matlab实验之显示地形数据_第2张图片

2.3使用纹理贴图

matlab实验之显示地形数据_第3张图片

你可能感兴趣的:(#,Matlab基础内容,matlab)