I am trying to label the outliers of the box plot with year number. in the following code, pre_1 is years 1950-2010 for only january, pre_2 is the same but for Feb, and so on to Dec. I am wondering how can i get the index of each outliers, the ydata gives me the outliers value, but I still cannot find the index.
pre12345101112=[pre_1 pre_2 pre_3 pre_4 pre_5 pre_6 pre_7 pre_8 pre_9 pre_10 pre_11 pre_12];
figure;boxplot(pre12345101112)
h = findobj(gcf,'tag','Outliers');
xdata = get(h,'XData')
ydata = get(h,'YData')
thanks in advance

 Respuesta aceptada

per isakson
per isakson el 17 de Sept. de 2014
Editada: per isakson el 17 de Sept. de 2014

2 votos

Try this
m = randn(48,12);
e = eps(max(m(:)));
boxplot( m )
h = flipud(findobj(gcf,'tag','Outliers')); % flip order of handles
for jj = 1 : length( h )
x = get( h(jj), 'XData' );
y = get( h(jj), 'YData' );
for ii = 1 : length( x )
if not( isnan( x(ii) ) )
ix = find( abs( m(:,jj)-y(ii) ) < e );
text( x(ii), y(ii), sprintf( '\\leftarrowY%02d', ix ) )
end
end
end
it labels the outliers

3 comentarios

ahmed shaaban
ahmed shaaban el 18 de Sept. de 2014
Editada: ahmed shaaban el 18 de Sept. de 2014
Perfect . Thanks a lot .
allan
allan el 12 de Ag. de 2017
Editada: allan el 12 de Ag. de 2017
What are the use of these two lines? e = eps(max(m(:))); ix = find( abs( m(:,jj)-y(ii) ) < e );
Also, is there a way to index the "subject" of the outliers instead of the 'value'?
Many thanks.
Robert White
Robert White el 9 de Sept. de 2021
This was very helpful, thank you! Worked great.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 16 de Sept. de 2014

Comentada:

el 9 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by