Problem getting handles structure to update in GUI
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am having a problem with the handles structure in a GUI. What I am doing is keeping a log of the current text entered by the user. Then, when an event is triggered, I plot this text on an axes along with a couple of line objects. Here is the code I am using to do this:
function addPhone(hObject, x)
handles = guidata(hObject);
set(handles.phoneInput_edittext,'String',[]);
m = get(handles.axes2,'YLim');
l1 = line([x(1) x(1)], m, 'Color', 'b', 'Parent', handles.axes2);
l2 = line([x(2) x(2)], m, 'Color', 'b', 'Parent', handles.axes2);
t = text(mean(x), mean([m(1) mean(m)]), 'String', handles.updStr, 'Color', 'b', ...
'HorizontalAlignment', 'center', 'Parent', handles.axes2);
handles.updStr = [];
guidata(hObject, handles);
I am also setting the String of the EditText back to empty, and also the variable handles.updStr, which contains my user string.
There are two problems. The first is that the handles structure for some reason does not update from within this function, so when the function ends, handles.updStr is not empty - it still contains the user input string.
The second problem is that there are intermittent problems accessing the handles class from within the function because text() sometimes behaves as expected, printing the text on the screen, and sometimes returns an error saying "Invalid parameter/value pair arguments", which I believe refers to a problem with the data I'm trying to use in the handles structure.
Does anyone know the problem here?
0 commentaires
Réponse acceptée
Gerd
le 7 Juin 2011
Hi Michael,
I also have sometimes a strange behaviour using the guidata(hObject) terminology. I started using for my own data
mydata = getappdata(gcf, 'mydata'); and
setappdata(gcf,'mydata',mydata);
You can save all your variables in the mydata structure. That helped a lot.
But be carefull always using the right figure(gcf).
Gerd
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Function Creation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!