get plotyy second axis handle

I know I can get the second axis handle for plotyy with
[AX,~,~] = plotyy(x1,y1,x2,y2)
and the handle is AX(2) but i use the plotyy function inside another function so AX is deleted because its a local variable
when i use gca (after running the function) in the command window I get what would be AX(1)
So my question is how to get the second axis handle after running the function

 채택된 답변

Paulo Silva
Paulo Silva 2011년 4월 13일

1 개 추천

AX=findall(0,'type','axes');
AX(2) %what you are looking for?!

댓글 수: 3

Zakary Stone
Zakary Stone 2011년 4월 13일
thanks i tried it and looked about this function and I think this will work for me
Zakary Stone
Zakary Stone 2011년 4월 14일
actually using
AX=findall(0,'type','axes')
what i am looking for is
AX(1)
thanks
Paulo Silva
Paulo Silva 2011년 4월 14일
You can compare the handles
AX=findall(0,'type','axes');
if AX(1)==gca
MySecondAxes=AX(2)
else
MySecondAxes=AX(1)
end
MySecondAxes %the handle you are interested in (not the current axes)

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

추가 답변 (2개)

Jarrod Rivituso
Jarrod Rivituso 2011년 4월 13일

1 개 추천

This also would work:
secondAxes = findobj('Type','axes','Color','none')

댓글 수: 4

Zakary Stone
Zakary Stone 2011년 4월 13일
this returns the result that i want but i don't get how it works after reading about it in the help files
but thanks
Jarrod Rivituso
Jarrod Rivituso 2011년 4월 13일
no problem. fyi, the reason this works is because plotyy works by creating two axes on top of one another, with the second axes' white background missing. so, you can easily find that second axes by looking for an axes that has it's 'Color' property set to 'none'
Zakary Stone
Zakary Stone 2011년 4월 14일
thanks for the explanation
this is exactly what i need(now that i know how it works)
sorry that i already gave the accepted answer check
Paulo Silva
Paulo Silva 2011년 4월 14일
All the solutions provided work just fine :)

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

Zakary Stone
Zakary Stone 2011년 4월 13일

0 개 추천

thanks for your responses i don't know whether your answers are right or wrong because i am still learning the the program and i'm not familiar with the functions you used
however i after continuing to reading through t help files i found a solution
get(gcf,'children')
this gives me a list of the handles
thanks

카테고리

도움말 센터File Exchange에서 Two y-axis에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by