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 件のコメント
Adam
Adam 2019 年 7 月 16 日
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