Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Variable must be a handle

Asked by Quang Thinh

Quang Thinh (view profile)

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
setappdata(hMainGui,'PlotxE',PlotxE);
setappdata(hMainGui,'PlotvE',PlotvE);
setappdata(hMainGui,'PlotxV',PlotxV);
setappdata(hMainGui,'PlotvV',PlotvV);

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.

Regards,

3 Comments

Vera

Vera (view profile)

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?

Thanks

Jan Simon

Jan Simon (view profile)

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)
Vera

Vera (view profile)

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 =)

Quang Thinh

Quang Thinh (view profile)

Tags

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson

Walter Roberson (view profile)

on 5 Sep 2013

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

0 Comments

Walter Roberson

Walter Roberson (view profile)

Contact us