Acessing imrect with another callback
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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 comentarios
Adam
el 16 de Jul. de 2019
And what was the result? Error? Nothing? Incorrect answer? Please post code as actual code, not as a screenshot which is not any use for anyone giving changes to the code.
linus Awuniji
el 16 de Jul. de 2019
Stephen23
el 16 de Jul. de 2019
linus Awuniji
el 16 de Jul. de 2019
"I have already created the box in one function and need to use another callback in expanding it"
The simple answer is to
- not use GUIDE, and
- 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
el 16 de Jul. de 2019
Respuestas (1)
Jan
el 16 de Jul. de 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 comentarios
linus Awuniji
el 16 de Jul. de 2019
Adam
el 16 de Jul. de 2019
Jan
el 16 de Jul. de 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.
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!