Filter löschen
Filter löschen

Global arrays using GUIDE

2 Ansichten (letzte 30 Tage)
Jay
Jay am 3 Mai 2016
Bearbeitet: VBBV am 4 Jul. 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 Kommentare
Jay
Jay am 4 Mai 2016
Bearbeitet: Jay am 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 am 4 Mai 2016
Bearbeitet: Adam am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 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 Kommentare
VBBV
VBBV am 4 Jul. 2018
Bearbeitet: VBBV am 4 Jul. 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 am 4 Jul. 2018
Bearbeitet: Jan am 4 Jul. 2018
@Vasishta Bhargava: Please open a new thread and post your code and a copy of the complete error message there.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by