Attempt to reference field of non-structure array
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hi, I'm trying to open a gui from other gui, by separate both works fine, but when I open the second guide and get some values that says 'Attempt to reference field of non structure array Error T1=get(handles.T,'String') ' Please help me My code
function T..Callback(hObject,evendata,handles)
....
T1=get(handles.T,'String')
채택된 답변
Walter Roberson
2016년 1월 12일
Each handles structure is associated with a particular figure. When you are using GUIDE, the handles structure that would be automatically referenced on your behalf would belong to the figure (GUI) that the graphics object is part of. That handles structure is not going to know anything about the handles structure of the other figure (GUI) unless you specifically passed in that information.
When the first GUI calls upon the second GUI, the figure handle of the second GUI will be returned to the caller in the first GUI. The first GUI can then use guidata() on the second figure's figure handle in order to get the second GUI's handles, and the first GUI can then write the first GUI's figure handle into the second GUI's handles. Then in the second GUI, when something is needed out of the first GUI, that recorded figure handle can be used to retrieve the first GUI's handles. For example,
%in first gui
fig1 = gcf(); %first GUI's figure handle
fig2 = SecondGUI(); %returns second GUI's figure handle
handles2 = guidata(fig2); %fetch second GUI's handles
handles2.fig1 = fig1; %record first GUI's figure handle
guidata(fig2, handles2); %and update second GUI's handles
and in second GUI
function some_callback(hObject, event, handles)
%in second GUI, handles refers to handles for second GUI
%and we stored a copy of the first GUI's figure handle there
fig1 = handles.fig1;
handles1 = guidata(fig1); %retrieve handles for first GUI
get(handles1.T, 'String') %reference to something in first GUI
Alternately, in the case where there is only one object with the tag T, you can skip all of this and instead use
function some_callback(hObject, event, handles)
T = findall(0, 'Tag', 'T'); %come out come out where-ever you are!
get(T, 'String')
findall can search all objects in all figures. It is not as efficient as the code from above, and you have complications if there are multiple objects with the same Tag.
댓글 수: 13
thanks walter, its working.
how to do the samething if we have more than two gui's,say we have 3 gui's .
@Sajid: Exactly the same way:
fig1 = gcf(); %first GUI's figure handle
fig2 = SecondGUI(); %returns second GUI's figure handle
fig3 = ThirdGUI(); %returns second GUI's figure handle
handles2 = guidata(fig2); %fetch second GUI's handles
handles2.fig1 = fig1; %record first GUI's figure handle
handles2.fig3 = fig3;
guidata(fig2, handles2);
handles3 = guidata(fig3); %fetch third GUI's handles
handles3.fig1 = fig1; %record first GUI's figure handle
handles3.fig2 = fig2;
guidata(fig3, handles3);
yeah thats perfectly fine walter,
but it is opening both second and third gui together.but ineed to open up in a sequence.....that is first gui opens second gui and second gui opens third .but i need first gui data in the third gui.
help me out please.
%in first gui
fig1 = gcf(); %first GUI's figure handle
handles1 = guidata(fig1);
fig2 = SecondGUI(); %returns second GUI's figure handle
handles2 = guidata(fig2); %fetch second GUI's handles
handles1.fig1 = fig1;
handles1.fig2 = fig2;
handles1.fig3 = [];
guidata(fig1, handles1);
handles2.fig1 = fig1; %record first GUI's figure handle
handles2.fig2 = fig2;
handles2.fig3 = [];
guidata(fig2, handles2); %and update second GUI's handles
%in second gui
function some_callback(hObject, event, handles2)
%in second GUI, handles refers to handles for second GUI
%and we stored a copy of the first GUI's figure handle there
fig1 = handles2.fig1;
handles1 = guidata(fig1); %retrieve handles for first GUI
fig2 = handles1.fig2;
fig3 = ThirdGUI(); %returns third GUI's figure handle
handles3 = guidata(fig3);
handles1.fig3 = fig3; %notify fig1 where fig3 is
guidata(fig1, handles1);
handles2.fig3 = fig3; %notify fig2 where fig3 is
guidata(fig2, handles2);
handles3.fig1 = fig1; %notify fig3 where fig1 and fig2 are
handles3.fig2 = fig2;
handles3.fig3 = fig3;
guidata(fig3, handles3);
i am getting the below error
>> Gui1
Undefined function or variable 'handles2'.
Error in Gui2>close_button_Callback (line 97)
fig1 = handles2.fig1;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Gui2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Gui2('close_button_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Notice in my code I named the third parameter of the callback as handles2 . I suspect you did not do that.
function close_button_Callback(hObject, eventdata, handles)
%in second GUI, handles refers to handles for second GUI
%and we stored a copy of the first GUI's figure handle there
handles2 = handles;
fig1 = handles2.fig1;
handles1 = guidata(fig1); %retrieve handles for first GUI
fig2 = handles1.fig2;
fig3 = ThirdGUI(); %returns third GUI's figure handle
handles3 = guidata(fig3);
handles1.fig3 = fig3; %notify fig1 where fig3 is
guidata(fig1, handles1);
handles2.fig3 = fig3; %notify fig2 where fig3 is
guidata(fig2, handles2);
handles3.fig1 = fig1; %notify fig3 where fig1 and fig2 are
handles3.fig2 = fig2;
handles3.fig3 = fig3;
guidata(fig3, handles3);
end
yeah walter , i did miss that.
you are genious ,thanks a lot
Sajid Afaque
2019년 4월 25일
편집: Jan
2019년 4월 25일
hi
its working , i am able to read data between gui's ,but the handles are only available for that function.
what should i do if i have to read data from gui 1 and based on that date display specific data in gui 3 as soon as gui 3 opens, that is in opening fcn of gui3
[MOVED from flags] its a different related question
@Sajid: Please use flags only to inform admins and editors about inappropriate contents like rudeness or spam. Thanks.
You find all you need in this thread already. To obtain data from the GUI1 use:
GUI1H = findobj(groot, 'flat', 'Tag', 'GUI1_Tag');
Gui1Handles = guidata(GUI1H);
...
Use the tag you gave your GUI1.
The mutual dependency of different GUIs is confusing and counter-intuitive. Prefer to use a multi-tabbed GUI or a larger interface, such that all values belonging together appear together.
ok i did not knew about flag.
it won't be repeated
Belmadnai issam
2019년 5월 21일
편집: Belmadnai issam
2019년 5월 21일
@Sajid: Please can you show me your example because it's not working i my GUIs
I have 4 GUIs it's and i want to pass data between it , it's complicated little bit, so please help me and thank you in advance
Walter Roberson
2019년 5월 21일
편집: Walter Roberson
2019년 5월 21일
The easiest way is to give each of the figure() a unique tag, and then when you need to refer to items in another gui, use findobj like Jan showed https://www.mathworks.com/matlabcentral/answers/263419-attempt-to-reference-field-of-non-structure-array#comment_698061 to locate the handle of the other gui. Then you can guidata() that handle to get to its handle list.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
