First time using imagesc and it seems to be completely changing my plot? Help!
7 views (last 30 days)
Show older comments
I basically have a bunch of points in range and angle such that they create concentric rings where on any given ring all points are the same radius away from the centre, and each point is an equal fraction of degrees away from its neighours on the same ring. When I convert these polar coordinates to cartesian x and y points and do a scatter plot, I get the below image as expected, where the maximum radius has been set at 100, thus my x axis goes from + to - 100 and my y axis from 0 to +100.

The problem arises when I introduce my function F. F has a different value (in decibels) for every concentric semicircle ring (i.e. it changes with radius but not angle). Its length is therefore equal to the number of different radius values that I have. However, I am wanting to plot a colour map such that I can see how F is changing within this geometry. Hence why I convert to x and y cartesian coordinates. To plot F on top of this though, I need a value of F for every x and y point.
So I essentially elongate the vector F at the same time as doing the polar->cartesian transformation, so that the value of F at a given radius r is placed alongside all x and y values that correspond to a point on that particular ring with radius r. It looks something like:
Fxy = NaN(1, length(F)*ang); %ang is just the number of points I have in angle for every ring
xPts = NaN(1, length(Fxy));
yPts = NaN(1, length(Fxy));
index1 = 1;
index2 = 1;
for radius = rStep:rStep:rMax
for angle = 0:angStep:pi
[x,y] = pol2cart(angle, radius);
Fxy(index2) = F(index1); %Set all of the points on this ring to the value of F for this particular radius
xPts(index2) = x;
yPts(index2) = y;
index2 = index2 + 1; %inner loop index
end
index1 = index1 + 1; %outer loop index
end
Finally, I simply try to plot this using imagesc. I am expecting essentially a rainbow, since F is changing as the radius extends. However, what I get is much different, and I don't understand why. First of all the axes are completely messed up. Secondly F seems to be plotted vertically starting from the right hand side and going across. This makes no sense considering my values of F and how they should be aligned to each x and y point (as I have ensured in my loop above).
figure
% scatter(xPts, yPts) %when I plot this I get the desired geometry as in first picture
imagesc(xPts,yPts,Fxy) %but when I plot this I get the below image
colorbar

Thank you very much for any help in advance!!
0 Comments
See Also
Categories
Find more on Polar 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!