Drew a circle for a specific point in my plot

50 views (last 30 days)
My objective is how to draw a circle for the min(PRESS). I wrote the following code for an ellipse, but I had to adjust the Xcenter and Ycenter handly, but I would rather do this in a automatically form, because if i change the min(PRESS) for example for the first two entries, the values changes and the elipse dont circle the point i want.
[mincumpress,nPC_imp] = min(PRESS(2:end,:))
x_aux = [0:maxpcs]';
hold on
yl = ylim; ylim([yl(1) yl(2)]);
xcenter = nPC_imp / xl(2) + 0.035
ycenter = mincumpress * (yl(2) - yl(1)) - 0.08
dim = [xcenter ycenter .05 .05];
hold on
xlabel('PC Number'); ylabel('PRESS');title('PCA-CV (ckf)');
Thanks for your time
jonas on 10 Jul 2018
Edited: jonas on 10 Jul 2018
Yea that's correct. Any method where the radius is connected to the axes will give that result, unless the xticks and yticks are equal. Your solution is very practical as the center is connected to the axes while the radius is 'disconnected' from the axes.

Sign in to comment.

Answers (1)

KSSV on 10 Jul 2018
Let C be the point, where you want to draw a circle.
N = 10 ;
x = 1:N ;
y = rand(N,1) ;
[val,idx] = max(y) ;
C = [x(idx) y(idx)] ;
plot(x,y) ;
hold on
R = 0.1 ; % Radius of circle
th = linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(2)+R*sin(th) ;
plot(xc,yc,'r') ;
axis equal
Tiago Dias
Tiago Dias on 10 Jul 2018
yes, thats what I said to jonas on the previous answer

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!

Translated by