Trying to plot a radial contour

I am trying to plot a 2x2 contour subplot, it is supposed to be circular, but I either get lines or no plot at all or an error saying my z needs to be a 2x2 array.
function F = ratio_rp_bf(R,theta,bD)
for r = 1:length(R)
for b = 1:length(bD)
F(b,r) = (16/3).*(1./bD(b)).*(1./R(r)).^3.*abs(sqrt((1./R(r)).^4-2.*(1./R(r)).^2.*cos(2.*theta(r))+1));
end
end
bD = [0.1, 1.0, 10, 100];
R = (1:1.25:5);
c = R;
a = 1/2*bD;
b = abs(sqrt(c.^2 - a.^2));
theta = abs(atan(b./a));
[F] = ratio_rp_bf(R,theta,bD);
for b = 1:length(bD)
figure(1)
subplot(2,2,b)
x = R.*cos(theta);
y = R.*sin(theta);
z = F;
[x,y,z] = meshgrid(x,y,z);
[C,h] = contour(R,theta,bD,x,y,z);
clabel(C,h);
grid on
end

 Accepted Answer

You try to visualize the contours of a 2 x 2 image. That should most likely look degraded. And note that for the values chosen each row is simply 1/10 of the previous row:
F(b+1, r) = F(b, r)/10
Is this correct?

More Answers (2)

Walter Roberson
Walter Roberson on 16 Feb 2013
Why are you trying to pass 6 parameters in to contour()? contour expects at most 4 numeric parameters (excluding name/value pairs)

7 Comments

I was following my professor's example. He didn't really explain why and it's the first time we've used the contour command, so I'm still trying to get a grasp on it. Because our original data is in polar coordinates, I use x and y to convert to cartesian coordinates, and z is supposed to equal our computations for F. When I try to plot using x,y,z, I get an error saying z needs to be a 2x2 array, which I understand, but my data sets aren't 2x2 arrays.
When you use
[x,y,z] = meshgrid(x,y,z);
you make it harder to debug, as you are overwriting the variables you are meshgrid()'ing.
Before you do the meshgrid(), what are size(x), size(y), size(z) ?
Why are you looping over bD when nothing in your loop is affected by the looping other than which subplot you are plotting in?
x, y, and z are 1x1. R is 1x1, theta is 1x5 and bD is 1x2. bD is somehow supposed to be the z axis, I don't know how though. R is supposed to be plotted along the x axis, and theta the y. z is equal to the computations.
How can bD possibly be 1 x 2 when just above you have
bD = [0.1, 1.0, 10, 100];
which is 1 x 4 ??
I don't know. R, x, and y should be 1x4 as well, but when I use the size command MATLAB gives me a different answer. But when I double click the variables in the workspace window, it shows the appropriate dimensions.
Have you tried restarting MATLAB? Then put in a breakpoint at the meshgrid line, and examine the size() and print the values of the variables to see how many entries show up and what they are.
I have, and the size() is the same, but the values print as 1x4 like they are supposed to do, and the computations are correct. I checked them by hand.

Sign in to comment.

Image Analyst
Image Analyst on 17 Feb 2013
I'm not really sure I follow what you're trying to do, nor do I know what sort of output ratio_rp_bf() creates, but if you just want to draw dircles, see the FAQ:
If F is an image that you created that's supposed to be a circular cone so that contours on it would be concentric circles, then please upload that image since I don't have ratio_rp_bf() which creates it.

5 Comments

The ratio_rp_bf function is at the very top of the posting.
Image Analyst
Image Analyst on 17 Feb 2013
Edited: Image Analyst on 17 Feb 2013
Oh you're right. But then wouldn't that make this a recursive function, since it's calling itself? Maybe I'm just not following it correctly because of the bad formatting. Where is the actual end of the ratio_rp_bf() function?
%this is the function the main program is calling to run all the computations F, for the length of bD, using R and theta which are dependent variables and which vary directly.
function F = ratio_rp_bf(R,theta,bD)
for r = 1:length®
for b = 1:length(bD)
F(b,r) = (16/3).*(1./bD(b)).*(1./R(r)).^3.*abs(sqrt((1./R(r)).^4-2.*(1./R(r)).^2.*cos(2.*theta(r))+1));
end
end
% This is the main program. After all the computations have been done, the output should be a 2x2 contour subplot in the form of a circle for each bD. The bD should cause a break to form in the plotted circle.
bD = [0.1, 1.0, 10, 100];
R = (1:1.25:5);
c = R;
a = 1/2*bD;
b = abs(sqrt(c.^2 - a.^2));
theta = abs(atan(b./a)); %finds the angle theta for each given radii (R)
[F] = ratio_rp_bf(R,theta,bD);% calls function to perform computaions
for b = 1:length(bD)
figure(1)
subplot(2,2,b)
x = R.*cos(theta); % conversion from polar coordinates to cartesian.
y = R.*sin(theta);
z = (x.^2+y.^2)<=R.^2;
[C,h] = contour(x,y,z,F);
clabel(C,h);
grid on
end
I get an error stating z needs to be size 2x2 or greater.
According to my professor, contour(R,theta,bD) should plot the contours of the expression F and it should be radial with breaks at each bD.
One of you has misinterpreted. The three-argument form of contour() is always X, Y, Z coordinates. To use specific contour levels, you need the two-input or four-input forms of contour(). See http://www.mathworks.com/help/matlab/ref/contour.html
Note that you have not included F in your contour() call.

Sign in to comment.

Categories

Asked:

on 16 Feb 2013

Community Treasure Hunt

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

Start Hunting!