MATLAB Answers

Quang Thinh

Variable must be a handle

Asked by Quang Thinh
on 5 Sep 2013

Hi guys

Currently working on GUI and stuff. I am learning a new command setappdata

I got stuck after this

PlotxE = plot([0 0]);
PlotvE = plot([0 0]);
PlotxV = plot([0 0]);
PlotvV = plot([0 0]);
hMainGui = getappdata(0, 'hMainGui');
%Set up data for storage

Basically, the error was

Error using setappdata
Value must be a handle.

Have been stuck and google around for good couple of hours. If someone can help me, that would be nice.



on 20 Sep 2013

I have the same error message and also no clue what it means. Did you find a solution, yet? Can you please share it?


Jan Simon
on 20 Sep 2013

@Vera: The error message means (or most likely means - better post a copy of the full message instead of referring to a short cut out part posted by another user), that hMainGui is not a handle of an existing HG-object. Then Matlab cannot set the ApplicationData of this object. Now it is your turn to find out, why this object is not existing anymore. Perhaps you forgot to update the ApplicationData of the root object:

setappdata(0, 'hMainGui', HandleOfMainGUI)
on 20 Sep 2013

@Jan: Thanks, it works now. My problem was, that I misunderstood the error message. I thought the problem was with the third input parameter because in doc this is called value. After I found out the problem is with the handle, it was fairly easy =)



No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 5 Sep 2013

You do not show the appdata for hMainGui being initialized. It would default to []


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!