How to save/access an axes's properties using the handles structure?

조회 수: 8 (최근 30일)
What is the syntax I can use to save an axes that I defined in a code file into the handles structure, and how can I access this handle from other code files?
  댓글 수: 2
Image Analyst
Image Analyst 2012년 5월 25일
Try the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F

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

채택된 답변

Stephen
Stephen 2012년 5월 25일
I made a script which uses
set(gca,'property','value','property2','value2')
and changes the default plot to look nicer.
Now, if you mean to say you have a figure with an axes, and h is the axes handle defined by one code. I believe you could do two things to get h from another piece of code. One is to set h as an output in the original code:
function h = myhandlefunction
h = plot(1:5);
end
then it will be in the work space if you call another function:
function another_function
h=myhandlefunction;
set(h,'color','yellow')
end
As long as you don't close the figure or delete the object that the handle references, this should work. You can also use findobj:
h = findobj(gca,'color','b');
set(h,'color','yellow')
to search for specific handles with matching properties. I hope I answered your question, good luck :)
  댓글 수: 1
Omair
Omair 2012년 5월 25일
Thank you very much for your answer. I'm rather new to MATLAB so I'm not very good with how functions interact with each other. I used the second method and it worked fine, however, what worked for me is:
h = findobj(0,'color','b'). I used the 0 handle, which is the current figure handle if I am not mistaken.
I have another inquiry that is closely related to my previous one, if you have the time I would be grateful.
According to my current understanding,If I use GUIDE to create a GUI, each component (i.e. axis, static text...etc) is given a handle by GUIDE that can be easily found. Now inside the m file generated by guide, I can call these handles using set() for example "set(handles.text2,'Color','b'). However if I create an axis inside this same code using for example axz=axes, the handle "axz" doesnt not seem to be saved into the handles structure and thus I cannot seem to call it to modify the axes, even from inside the m file created by GUIDE. How can I save this new handle into the handles structure?

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

추가 답변 (1개)

Stephen
Stephen 2012년 5월 25일
I used to know how to answer this better, and maybe a bit of reading will answer based on my advice. In each function of the GUI you must updates the structured variable that contains the handles or other information. a structured variable is something like s.handle and s.value, so you can pass the variable s throughout your GUI and it contains multiple things in it. Try searching youtube for a GUIDE tutorial, I think that's where I learned how to do it correctly. So, in that case, you'd have to include your handle axs into the overall gui handles structure to pass it along.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by