필터 지우기
필터 지우기

Global arrays using GUIDE

조회 수: 2 (최근 30일)
Jay
Jay 2016년 5월 3일
편집: VBBV 2018년 7월 4일
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
Jay
Jay 2016년 5월 4일
편집: Jay 2016년 5월 4일
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 2016년 5월 4일
편집: Adam 2016년 5월 4일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2016년 5월 4일
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
VBBV
VBBV 2018년 7월 4일
편집: VBBV 2018년 7월 4일
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 2018년 7월 4일
편집: Jan 2018년 7월 4일
@Vasishta Bhargava: Please open a new thread and post your code and a copy of the complete error message there.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by