Polar coordinate plot with color

조회 수: 6 (최근 30일)
Dave
Dave 2012년 1월 22일
Hi all,
I am trying to create points on the polar grid and color code each point. The MATLAB polar function allows one color per call, so I am looping roughly 15,000 times to generate the figure I need.
The section of code below takes 20 minutes to execute. Are there ways to make this code more time efficient given the limitation of the polar function?
David
%-------------------------
% polar plots
map=colormap; close
theta = phase1(mask).*pi/180;
rho = amplitude1(mask);
gof = gof1(mask);
ccode = round(gof*63+1);
%-------------------------
for i=1:length(theta) %15,000
if i==1
figure
h = polar(theta(i),rho(i),'o');
set(h, 'MarkerFaceColor', map(ccode(i),:));
else
h = polar(theta(i),rho(i),'o');
set(h, 'MarkerFaceColor', map(ccode(i),:));
end
end
%-------------------------

채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 22일
Is your code perhaps missing a "hold on" ?
Could you polar() once to get the background, hold on, then scatter() of pol2cart() of everything at once to draw the points?
The first point you should polar() should be the one with the largest rho so that you get the rings drawn correctly.
By the way, with the code you have, why not call figure once first before the loop, and then your loop would not need any "if" statement?
  댓글 수: 1
Dave
Dave 2012년 1월 23일
While I was prepping my code for posting, I deleted a "hold on" by mistake. Thank you very much for your valuable comment. Your suggestion did the trick!
Here is a much more concise and time efficient code that generates the figure I need instantly.
theta = phase1(mask).*pi/180;
rho = cbf1(mask);
gof = gof1(mask);
[X,Y] = pol2cart(theta,rho); S = 15;
figure
h_fake = polar(theta_,1500*ones(size(theta_))); % set radius to 1500
hold on
set(h_fake, 'Visible', 'Off');
scatter(X, Y, S, gof,'filled');
colorbar
Cheers,
David

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by