GUIDE handles not created automatically

8 vues (au cours des 30 derniers jours)
Dennis
Dennis le 13 Oct 2022
Commenté : Dennis le 17 Oct 2022
Hey MATLAB-Community!
I'm a new MATLAB user (started using it at a company) and I'm facing a problem. I was given a project, that once ran fine, but now there is a "Dot indexing is not supported for variables of this type." error. I know where it comes from, when debugging, I can see that handles is "[]", even though it should be a struct. Of course, dot indexing won't work with an empty cell.
I have an .m file and a .fig file, and a hand.mat that loads handles into the workspace. After starting the program again, handles is an empty cell again, tho. When just xecuting the .m file, I get an empty figure window. When opening the .fig file directly, the layout is correct, but whenever I try to interact with it, I get that dot indexing error.
Now, my question is: How do I correctly start a GUI-program, that was made with GUIDE? How do I make sure those handles and callbacks are correctly configured? A general explanation how it SHOULD work would be sufficient... Documentation on this is not that great.
Kind regards
Dennis
EDIT: I can further narrow down the problem. The "handles" struct gets created automatically, but the problem is, that the handle doesn't get passed to the callback functions correctly, because if I check "pause on error" (run button dropdown menu), then I can see, that inside the callback functions workspace, "handles" is empty again.
EDIT 2: I'm starting to turn this from a question to a tutorial xD I tried working around the problem by writing "handles = guihandles" at the beginning of a callback funtion, but that feels wrong and just shifts the problem to the next place... But then, handles isn't empty anymore. It just doesn't have all the fields it should have.
  4 commentaires
Rik
Rik le 17 Oct 2022
gcf is fine (since the GUI figure will be the current figure if you interact with it), although gcbf is safer.
gca should generally be avoided in favor of explicit axes handles, even outside the context of GUIs.
Dennis
Dennis le 17 Oct 2022
Yes, but the problem is: The Tag changes, when I do with the program what I wanna do. The empty "axes" has a different tag than the axes, once I filled my data in. I have no idea why, but, tbh, I don't even care at this point xD The program works, and I'll probably never use GUIDE again ^^ Thanks for your tips. Helped me understand this mess better :)

Connectez-vous pour commenter.

Réponses (3)

Image Analyst
Image Analyst le 13 Oct 2022
Chances are you have a "clear" command inside your function that blows it away. Get rid of that.
If you can attach the .fig and .m files, along with any data file(s) needed to run it, then I could probably fix it.
  9 commentaires
Image Analyst
Image Analyst le 17 Oct 2022
Modifié(e) : Image Analyst le 17 Oct 2022
There is a callback property in the Property Inspector for each button that gives the name of the function. However if it's getting in at all, the function name is right. Here is an example of one from my .fig file:
@(hObject,eventdata)WipeHeight('btnAnalyze_Callback',hObject,eventdata,guidata(hObject))
where WipeHeight is the name of my main app and btnAnalyze is the name of the pushbutton. Make sure yours looks similar, especially the stuff for hObject and to the right.
And make sure you're always referencing handles, with a final 's', not handle without a final 's'.
Rik
Rik le 17 Oct 2022
They will be in the callback property of the object. But if you don't trust them, put this at the start of your function:
hObject = gcbo; % Get callback object
handles = guidata(hObject); % This will cascade up until it finds a parent figure

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 13 Oct 2022
When opening the .fig file directly, the layout is correct, but whenever I try to interact with it, I get that dot indexing error.
You cannot launch a GUIDE-based GUI by opening the .fig file directly. Doing so bypasses the setup code in the accompanying .m file and that makes the GUI non-functional.
The "handles" struct gets created automatically, but the problem is, that the handle doesn't get passed to the callback functions correctly, because if I check "pause on error" (run button dropdown menu), then I can see, that inside the callback functions workspace, "handles" is empty again.
Did whoever wrote the code define the callback functions using the GUIDE editor or did they include a line of code that sets the callback function at runtime? If the latter I suspect they may have specified the callback function in such a way that it uses a copy of the handles structure as it existed when that line of code was executed, ignoring any changes made afterwards in other callback functions. Usually that type of problem manifests as the handles structure missing one new field, but it could manifest as the struct being empty.
If you can't post the GUI here but you also can't determine the cause of the problem you may want to contact Technical Support directly using the Contact Support link under the Get Support heading at the end of this page and work with them to investigate.

Image Analyst
Image Analyst le 13 Oct 2022
"How do I correctly start a GUI-program, that was made with GUIDE?"
You can either
  1. click the green run triangle when looking at the m-file in MATLAB, or
  2. click the green run triangle when looking at the fig-file in GUIDE, or
  3. type the name of the m-file in the Command Window.
But do NOT double click the .fig file in the Current Folder list of filenames.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by