Polar Contour not interpolating between values

4 views (last 30 days)
I have a function that I found online:
% POLARCONT Polar contourf plot
% Richard Rieber
% rrieber@gmail.com
% April 4, 2007
% Updated June 15, 2007
% function [C,h] = polarcont(r,theta,z,N,s)
% Purpose: This function creates polar contourf plots on the current active
% figure
% Inputs: o r - Radius vector of length m
% o theta - Angle vector in radians of length n
% o z - Magnitude at the points specified in r and theta of
% size m x n
% o N - The number of contourfs to plot [OPTIONAL]
% o s - Linespec as described in PLOT [OPTIONAL]
% Outputs: o C - returns contourf matrix C as described in contourfC
% o h - Column vector H of handles to LINE or PATCH objects,
% one handle per line.
% - Both C and h can be used as inputs to CLABEL
% - Colors are defined in colormap
% - Treat this function as a standard contourf plot
function [C,h] = polarcont(r,theta,z,N,s)
[a,b] = size(z);
if a ~= length(r)
error('r is not the same length as the first dimension of z')
if b ~= length(theta)
error('theta is not the same length as the second dimension of z')
x = zeros(a,b);
y = zeros(a,b);
for j = 1:a
for k = 1:b
x(j,k) = r(j)*cos(theta(k));
y(j,k) = r(j)*sin(theta(k));
if nargin == 3
[C,h] = contourf(x,y,z);
elseif nargin == 4
[C,h] = contourf(x,y,z,N);
elseif nargin == 5
[C,h] = contourf(x,y,z,N,s);
error('Incorrect number of inputs')
However, I have a hard time getting the plot to look how I want. The colors do not interpolate between values, and if I increase the number (N) contours, I end up getting a lot of black lines all over my graph. Can someone take a look at my code below, and tell me if there is anything that I have that causes the colors to not interpolate between values? I hate the sharp transitions. Another option would be getting rid of all the black lines that appear if I choose 100 contours. I think I am missing something obvious.
close all
data1 = xlsread('C:\Users\data.xlsx','theta');
data2 = xlsread('C:\Users\data.xlsx','r');
data3 = xlsread('C:\Users\data.xlsx','z');
t1 = data1(1,:);
r1 = data2(:,1);
z1 = data3(:,:);
myColorMap = colormap;
myColorMap(1,:) = [1 1 1];
caxis([0 10])
beta = 0.8;
axis equal
axis off
Those sharp transitions you see aren't real. There are plenty of color values of 3.9 and 4 that are colored the same as if they were 0 or 1 or 2. Figure is attached. How can I remove the isolines?

Answers (0)


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!