Smooth contours of a colormap

4 views (last 30 days)
Ailita94
Ailita94 on 15 May 2019
Answered: Bjorn Gustavsson on 15 May 2019
Hello,
I have an mxn matrix and i am plotting a filled contour map.
tbl=[360, 365, 400, 430, 470, 495, 535, 565, 585, 620, 620, 660;365, 400, 400, 465, 495, 515, 540, 565, 585, 620, 620, 350;400, 405, 465, 470, 495, 515, 555, 565, 585, 355, 355, 360;430, 465, 480, 495, 515, 540, 565, 565, 360, 360, 360, 365;480, 490, 505, 515, 540, 565, 565, 360, 365, 365, 370, 390;510, 530, 555, 560, 565, 565, 365, 365, 370, 390, 400, 405;560, 565, 575, 580, 585, 585, 370, 390, 400, 415, 425, 440;590, 590, 595, 595, 595, 595, 595, 410, 425, 445, 460, 475;625, 625, 635, 655, 655, 655, 655, 625, 465, 485, 485, 500;675, 675, 690, 690, 690, 690, 690, 690, 590, 520, 520, 550;705, 705, 705, 705, 705, 705, 705, 705, 705, 570, 570, 570;755, 755, 755, 770, 770, 770, 770, 770, 755, 705, 600, 600]
x=[0:5:55];
y=[0:5:55];
contourf(x,y,tbl)
shading flat
I would like the contours to be smooth which is not the case, I have to interpolate but how can I build the X and Y matrix to use the interp2 function ?
tbl is an intensity at the point (x,y).
Thanks

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 15 May 2019
Why do you want your contours to be smooth? You have some idea that the surface doesn't have corner-like edges where slopes in different directions connect - how are we to know what's suitable smoothing when we only see the 12 x 12 data points you have?
You could try to interpolate your data:
xi = 0:.5:55;
yi = 0:.5:55;
tbli = interp2(x,y,tbl,xi,yi','cubic'); % try 'linear' too...
contour(xi,yi,tbli)
or if you have the spline-toolbox you could try more advanced interpolation or fitting functions. You could also use:contour-line-smooting, or Contour-line-smooting-local-regression. But those are not guaranteed to give you the results
you wish...
HTH

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!