Plotting a 2D terrain

3 views (last 30 days)
Joseph
Joseph on 29 Sep 2014
Edited: Star Strider on 29 Sep 2014
Hello,
How do I create a 2D plot from a array of data?
I have a square matrix [k,k]. How do I create a 2D Plot from the resulting matrix (T) and fill in different colors for each of the different heights (0, 1 & 2)?
Code thus far:
clear all close all
clc
k = input('Size of Matrix (k by k): '); %Enter in 10 for k
H0 = 0; H1 = 1; H2 = 2;
T = zeros([k, k]);
T(:,:) = H0; T(1:5,1:5) = H1; T(6:10,6:10)= H2;
disp(T);

Answers (1)

Star Strider
Star Strider on 29 Sep 2014
Edited: Star Strider on 29 Sep 2014
This works:
k = 10; % Replace this with your ‘input’ line
T = zeros([k, k]);
H0 = 0; H1 = 1; H2 = 2;
T(:,:) = H0; T(1:5,1:5) = H1; T(6:10,6:10)= H2;
figure(1)
surf(T)
view([0 90])
axis tight
colormap(lines(3))
colorbar('YTick',[1/3 1 5/3], 'YTickLabel',{'0' '1' '2'})
produces:

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!