Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Acessing imrect with another callback

조회 수: 1 (최근 30일)
linus Awuniji
linus Awuniji 2019년 7월 16일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi need to expand the imrect box by certain dimensions. I have already created the box in one function and need to use another callback in expanding it. Please , I need a clue. I have tried the code below.
  댓글 수: 6
Stephen23
Stephen23 2019년 7월 16일
편집: Stephen23 2019년 7월 16일
"I have already created the box in one function and need to use another callback in expanding it"
The simple answer is to
  1. not use GUIDE, and
  2. use nested functions.
Writing your own GUI means that you can easily do what you requested. Otherwise you will need to use handles and guidata.
linus Awuniji
linus Awuniji 2019년 7월 16일
@Stephen Cobeldick the code is for a guide app.. Let me know if you need the fig and other data.

답변 (1개)

Jan
Jan 2019년 7월 16일
It is a bad idea to set the AppData of the root object. This has the sme disadvantages as global variables. The complete communication inside your GUI work over this indirection and this impedes debugging massively. GUIDE offers the method to store all relevant data inside the figure using the guidata command.
You can store values in the handles struct easily. This struct is provided as input in all callbacks. Unfortunately you overwrite it in lines like this:
function button_process_Callback(hObject, eventdata, handles)
handles = guihandles;
This is a bad idea.
Use fullfile to create files names, because this is safer than the concatenation using [] .
You have posted the text of the error message, which explains where the error occurs, but is there a detail about what the problem is? What is "h" in
api = iptgetapi(h); % Also set the box to be that size
I do not see a definition of h in this callback. So maybe all you need to do is to insert this definition.
Nevertheless, I would not use a code based on the communication over global data for productive work. Therefore I strongly recommend to replace all setting and getting of AppData of the root object by storing the data inside the figure.
  댓글 수: 3
Jan
Jan 2019년 7월 16일
What h is created in another callback, it is not visible in the failing line. Follow Adam's link to learn how to share data between callbacks. Do not use the root object 0 to share data with getappdata/setappdata. This is a really bad idea.

Community Treasure Hunt

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

Start Hunting!

Translated by