In Matlab: How to create a 2d map from a 3 columns file

Relatively new to Matlab, I've been tryin to create a 2d map from a 3 columns file (x coord, y coord, value of cell (x,y)) but not sure how to proceed.
For example:
1901 0 1
1901 -10 2
1901 -20 3
1902 0 -1
1902 -10 3.5
1902 -20 1.5
1903 0 5
1903 -10 -3
1903 -20 0
Thanks in advance for any help!

 Accepted Answer

data = [1901 0 1
1901 -10 2
1901 -20 3
1902 0 -1
1902 -10 3.5
1902 -20 1.5
1903 0 5
1903 -10 -3
1903 -20 0 ] ;
x = data(:,1) ; y = data(:,2) ; z = data(:,3) ;
nx = length(unique(x)) ;
ny = length(unique(y)) ;
X = reshape(x,[ny,nx]) ;
Y = reshape(y,[ny,nx]) ;
Z = reshape(z,[ny,nx]) ;
pcolor(X,Y,Z)
shading interp
colorbar

2 Comments

Thank you so much for your help KSSV!
It produced exactly what I needed.
KSSV
KSSV on 15 Jul 2020
Edited: KSSV on 15 Jul 2020
Thanks is accepting/ voting the answer.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 13 Jul 2020

Edited:

on 15 Jul 2020

Community Treasure Hunt

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

Start Hunting!