pbj0812의 코딩 일기

[MATLAB] griddata 사용법 본문

ComputerLanguage_Program/MATLAB(OCTAVE)

[MATLAB] griddata 사용법

pbj0812 2018. 9. 3. 23:04

clear all; close all; clc;

[lon lat zeta] = textread('G:\2016_UM\glob_map.dat');

%파일 읽기 lon, lat, zeta 한 줄 형태


a = 1321
LAT = reshape(lat,a,length(lat)/a);
LON = reshape(lon,a,length(lon)/a);
ZETA = reshape(zeta,a,length(zeta)/a);

% 실제 형태 n*m 으로 변환


pcolor(LON,LAT,ZETA);
shading flat

x = 1:a;
y = 1:length(lat)/a;
x_v2 = linspace(LON(1),LON(end),620);
y_v2 = linspace(LAT(1),LAT(end),807);
[X,Y]=meshgrid(x_v2,y_v2);

% interpolation 범위 지정


zeta_int = griddata(LON,LAT,ZETA,X,Y);

% griddata(기존x, 기존y, 변환할정보, 바꿀x, 바꿀y)


X_write = reshape(X,807*620,1);
Y_write = reshape(Y,807*620,1);
Z_write = reshape(zeta_int,807*620,1);

box(:,1) = X_write;
box(:,2) = Y_write;
box(:,3) = Z_write;

fid=fopen('glob_map_int.dat','wt');
for i=1:length(X);
fprintf(fid,'%15.6f %15.6f %15.6f\n',box(i,:));
end
fclose(fid)

% ascii 저장

Comments