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,

4 Kommentare

Vera
Vera am 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
Jan am 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 am 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 =)
linus Awuniji
linus Awuniji am 17 Jul. 2019
@ Jan, I am having a similar trouble to that you just adressed here. But Im still a bit lost, what do you mean by HANDLE OF MAIN GUI. I need to save imrect and access it in another call back where i can naipulate it
.
function Valiste_roi_Mic(hObject, eventdata, handles)
handles=guihandles;
getappdata(0, 'Microscope_Image')
handles.imrect = imrect(gca, [0 0 50 50]);
handles.imrect = getappdata(handles.imrect)
api = iptgetapi(handles.imrect);
api.addNewPositionCallback(@(p) title(mat2str(round(p))));
api.addNewPositionCallback(@(p) setappdata(0,'coordinates',p));
api.addNewPositionCallback(@(p) button_plot_Callback(hObject, eventdata, handles));
fcn = makeConstrainToRectFcn('imrect',...
get(gca,'XLim'),get(gca,'YLim'));
api.setPositionConstraintFcn(fcn);
% THIS IS THE PART YOU PROPOSED.
setappdata(0, 'handle.imrect', hamsteri_OpeningFcn)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 5 Sep. 2013

0 Stimmen

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

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 5 Sep. 2013

Kommentiert:

am 17 Jul. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by