First time using imagesc and it seems to be completely changing my plot? Help!

8 visualizaciones (últimos 30 días)
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!!

Respuestas (1)

darova
darova el 18 de Abr. de 2020
You Fxy matrix should be 2D. No for loop is needed
[x,y] = pol2cart(angle,radius);
[Fxy,~] = mehsgrid(F,radius);
imagesc(x,y,Fxy)
  5 comentarios
Orla Lennon
Orla Lennon el 24 de Abr. de 2020
Hi, yes I had tried your suggestion and it hadn't worked for the dimensions reason. The second meshgrid seems to help, (although oddly enough when I run your code there is no red in my plot?)
The problem is that when I run this for my actual vectors which have many more points so a lot finer divisions, I just get a black hemisphere. I think this might be all the lines joining together. Is there a way to get rid of them?
darova
darova el 24 de Abr. de 2020
TO get rif of black lines try
pcolor(x,y,z,'edgecolor','none')

Iniciar sesión para comentar.

Categorías

Más información sobre Polar Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by