Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Acessing imrect with another callback

1 vue (au cours des 30 derniers jours)
linus Awuniji
linus Awuniji le 16 Juil 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaires
Stephen23
Stephen23 le 16 Juil 2019
Modifié(e) : Stephen23 le 16 Juil 2019
"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 le 16 Juil 2019
@Stephen Cobeldick the code is for a guide app.. Let me know if you need the fig and other data.

Réponses (1)

Jan
Jan le 16 Juil 2019
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 commentaires
Jan
Jan le 16 Juil 2019
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