How to get smooth contour plot using any interpolation scheme?

4 views (last 30 days)
I am trying to plot the contours of using spline cubic interpolation method. The problem I have that I don't get smooth contours lines. Any help will be appreciated. Here is my code:
clear all;
clc;
data = xlsread('Trial1.xlsx');
rlt = data ;
[height, width] = size(data);
[x,y] = meshgrid(0:5:width,0:5:height);
x(:,1) = 1; y(1,:) = 1;
z(1,1) = data(1,1);
for i = 1:height/5
z(i+1, 1) = data(5*i, 1);
end
for j = 1:width/5
z(1, j+1) = data(1, 5*j);
end
for i = 1:height/5
for j = 1:width/5
z(i+1,j+1) = data(5*i,5*j);
end
end
[x1,y1] = meshgrid(1:width, 1:height);
z1 = interp2(x, y, z, x1, y1, 'spline');
for i = 1:height
for j = 1:width
if ~(data(height-i+1,j) > 0 )
rlt(i,j) = z1(height-i+1,j);
else
rlt(i,j) = data(height-i+1,j);
end
end
end
% figure; mesh(x1,y1,z1); xlabel('longitude'); ylabel('latitude');
% F = [.05 .1 .05; .1 .4 .1; .05 .1 .05];
% ZC = conv2(rlt,F,'same');
xlswrite('digital_value.xlsx', rlt);
figure;
%contour(rlt,20);
[C,h] = contour(rlt);
clabel(C,h);
set(h, 'LevelList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19], ...
'TextList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])

Answers (0)

Categories

Find more on Contour Plots 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!