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

14 次查看(过去 30 天)
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!

采纳的回答

KSSV
KSSV 2020-7-14
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 个评论
Tony
Tony 2020-7-15
Thank you so much for your help KSSV!
It produced exactly what I needed.
KSSV
KSSV 2020-7-15
编辑:KSSV 2020-7-15
Thanks is accepting/ voting the answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by