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 件のコメント
Sajid Afaque
2019 年 4 月 17 日
thanks walter, its working.
how to do the samething if we have more than two gui's,say we have 3 gui's .
Jan
2019 年 4 月 17 日
@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);
Sajid Afaque
2019 年 4 月 17 日
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);
Sajid Afaque
2019 年 4 月 17 日
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
Walter Roberson
2019 年 4 月 17 日
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
Sajid Afaque
2019 年 4 月 17 日
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
Jan
2019 年 4 月 25 日
@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.
Sajid Afaque
2019 年 4 月 30 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
