Unrecognised handles in set

I'm trying to write a GUI which takes values from four input boxes and performs a calculation then sends the calculated values to four separate static text boxes. I am able to read the information from the input boxes fine and perform the calculation. The problem comes when I try and get the m file to set the values of the four static text boxes using
pump_result=num2str(pump);
set(handles.output_pump_freq,'String',pump_result);
I get an error saying "Reference to non-existent field 'output_pump_freq'.
This only happens when I run the program without debugging it. When I debug just before and run through these steps then the code works fine. It then works whenever I try to run this afterwards so long as I don't close the GUI. When I close the GUI the same problem occurs until I have run the program in debug mode. Have I not defined something properly?

1 Comment

Jan
Jan on 11 Oct 2011
Somehow you seem to use a variable |handles| without the fiels |output_pump_freq|. How do you set (and store) the |handles| variable?

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 11 Oct 2011
"This only happens when I run the program without debugging it." Did you double click the .fig file in Windows Explorer to run it? If that is the case, the handles of the GUI is not properly initialized. Try to run the corresponding .m file for the GUI directly.

8 Comments

Great thanks.
Is there a way that I could initialise the GUI handles properly so it would work if I just double click on the .fig file?
Maybe in theory, but I haven't seen anyone do it. By the time you got through the changes and restrictions you would need to deal with for this, you might as well just skip using GUIDE.
Jan
Jan on 11 Oct 2011
I do not understand the benefit of double clicking on the FIG file. This question appears repeatedly and I'm more and more confused, why users want to do this. Why is clicking FIG files such appealing?
@Jan, because, at least from one OP, his professor insists to be able to double click a file and run the file. If he double clicks the .m file, an editor with the .m code will be brought up and the professor will be confused. It's even more confusing if the professor has to start MATLAB, right click the .m file and then click 'Run'.
Provide a batch or shell script that starts matlab with the -r option?
Jan
Jan on 12 Oct 2011
@Fangjun: Thanks for the explanation. Couldn't we patch the professor?
@Walter: The FIG file is a MAT file, such that it is actually a struct. If double clicking the FIG file opens a figure, an interpreter must have been started implicitely. Then the CreateFcn should be able to perform a proper initialization. Do I understand correctly, that only GUIDE is does not know, how to insert the initialization code in the required callback?
I never use GUIDE. When I need to double click on an icon, I compile a stand-alone application, or a batch with -r. So I'm just asking, because the evergreeny fig-file clicking seems to be trivial and unsolved.
Did you guys notice that the link in my answer is mathworks.fr (assume France)? If I click that link, I won't be able to edit it. The page indicates I am not logged in.
@Fangjun: just replace the .fr with .com to get the page you want.
@Jan: I have not traced down whether it would be the CreateFcn or OpenFcn that would be involved. Either way, which-ever function, would have to refer to a function that is coded as a series of commands in a string in the appropriate Callback, or is coded as a function handle that is either already in scope or can be brought in to scope (e.g., because it is a separate .m file). I haven't tracked down the extent to which a function body itself is stored if you store a function handle in the .mat file.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 11 Oct 2011

Community Treasure Hunt

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

Start Hunting!