Effacer les filtres
Effacer les filtres

Global arrays using GUIDE

2 vues (au cours des 30 derniers jours)
Jay
Jay le 3 Mai 2016
Modifié(e) : VBBV le 4 Juil 2018
I have an array (1,3) of values in the edit box 4 callback function (HMS1).
Similarly I have another array in the edit box 6 callback function (again a (1,3) array labelled HMS2).
Now at the end of the edit box 6 callback function I have the commands
LST = zeros(1,3) % Initialize the array
LST(1,1) = HMS1(1,1) + HMS2(1,1)
During runtime I have the error 'Undefined function or variable 'HMS1'.'
LST is initialised (with zeros) but not populated (values not added and populated).
The only reason I can perceive is that this is due to the edit box 4 callback functions array is not being referenced.
Is this correct?
If so how do I declare an array value to be a global type?
I have tried to initialize HMS1 and HMS2 in the opening function and still have the same issue.
  3 commentaires
Jay
Jay le 4 Mai 2016
Modifié(e) : Jay le 4 Mai 2016
Thanks Stephen.
I appreciate that you directed me to the required reading rather than just giving me the answer.
After reviewing the information you attached I can not see how to obtain values from another function that is not used in a figure.
The values I require to be accessed are not outputted to a figure.
All relate to obtaining values from a figure. I have also tried to find where arrays (or even single values) are referenced between functions and could not find anything useful.
Adam
Adam le 4 Mai 2016
Modifié(e) : Adam le 4 Mai 2016
Your whole GUIDE file, containing the two callbacks you mention in your question, is the figure. The handles structure that gets passed to every callback as discussed in the above link as one method for sharing data amongst callbacks is the one I generally use.
guidata allows you to set and retrieve data stored in the handles structure.
You have to use it with care, never overwrite any of the existing data on handles (the GUI objects I mean, not something you add yourself) and never ever pass anything other than the full handles struct to the guidata function.
Other than that the handles structure is just a christmas tree, you can hang whatever you want on it, use guidata to save it back into the main 'figure' and then in your next callback the 'handles' argument you receive will include the data you previously attached to it.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 4 Mai 2016
And an explicit implementation of the methods explained in the links Stephen has posted:
function editbox4callback(hObject, EventData)
handles = guidata(hObject);
HMS1 = rand(1, 3);
handles.HMS1 = HMS1;
guidata(hObject, handles);
end
function editbox6callback(hObject, EventData)
handles = guidata(hObject);
HMS2 = rand(1, 3);
HMS1 = handles.HMS1;
disp(HMS1 + HMS2);
end
  3 commentaires
VBBV
VBBV le 4 Juil 2018
Modifié(e) : VBBV le 4 Juil 2018
Sorry to interrupt in this thread. But I have similar problem with array handling in GUI. when I implement the code shown by Jan, I get an error "Reference to non existent field, A = handles.A even though I have that data array present in callback ...where A is data array. I get this error in the CellEditcallback
Jan
Jan le 4 Juil 2018
Modifié(e) : Jan le 4 Juil 2018
@Vasishta Bhargava: Please open a new thread and post your code and a copy of the complete error message there.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by