Drew a circle for a specific point in my plot

Hi,
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.
load('PRESS')
[mincumpress,nPC_imp] = min(PRESS(2:end,:))
x_aux = [0:maxpcs]';
figure
plot(x_aux,PRESS,'-b','LineWidth',2);
hold on
plot(x_aux,PRESS,'.r','MarkerSize',15);
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];
annotation('ellipse',dim,'Color','red')
hold on
xlabel('PC Number'); ylabel('PRESS');title('PCA-CV (ckf)');
Thanks for your time

6 件のコメント

jonas
jonas 2018 年 7 月 10 日
If you have the image processing toolbox, then for circles you could use
viscircles([Xcenter Ycenter],R)
instead of the annotation.
Tiago Dias
Tiago Dias 2018 年 7 月 10 日
編集済み: Tiago Dias 2018 年 7 月 10 日
I don't but i resolved by problem by doing just
plot(nPC_imp,mincumpress,'O','Color','red','MarkerSize',25);
It drews a circle O on the specific point i want.
jonas
jonas 2018 年 7 月 10 日
That's a practical workaround! :)
Tiago Dias
Tiago Dias 2018 年 7 月 10 日
viscircles for me does a vertical elipse, not a circle. the "Yraidus is way bigger than the xradius"
Tiago Dias
Tiago Dias 2018 年 7 月 10 日
If You use viscircles, it does what I showed on the picture? a vertical elipse? or it really does an circle?
jonas
jonas 2018 年 7 月 10 日
編集済み: jonas 2018 年 7 月 10 日
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.

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2018 年 7 月 10 日

0 投票

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

3 件のコメント

Tiago Dias
Tiago Dias 2018 年 7 月 10 日
With your solution I have this, so the first plot the limits are modified, and I dont like that, if I disable axis equal I got what vircircle does. I prefer my plot with O but thanks for your time
KSSV
KSSV 2018 年 7 月 10 日
YOu can go for markers with circle i.e O and specify its size.
Tiago Dias
Tiago Dias 2018 年 7 月 10 日
yes, thats what I said to jonas on the previous answer

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2018 年 7 月 10 日

コメント済み:

2018 年 7 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by