Hi there I am trying to link two guis together , I have successfully transfered data between them using setappdata and getappdata But I've got error when trying set data into table (Reference to nonexistent field)
if true
function results_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to results (see VARARGIN)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
a= getappdata(0,'a');
b=getappdata(0,'b');
d=zeros(size(a,1),size(b,2));
set(handles.uitable1,'Data',d)
choice=getappdata(0,'choice');
switch choice
case 1
if size(a)==size(b)
r=a+b;
set(handles.uitable1,'Data',r)
else
set(handles.text1,'string','lenghts must agree')
end
case 2
if size(a)==size(b)
r=a-b;
set(handles.uitable1,'Data',r)
else
set(handles.text1,'string','lenghts must agree')
end
case 3
if size(a,2)==size(b,1)
r=a*b;
set(handles.uitable1,'Data',r)
else
set(handles.text1,'string','inner dimensions must agree')
end
case 4
set(handles.uitable1,'Data',inv(a))
case 5
end
end

12 件のコメント

Image Analyst
Image Analyst 2016 年 3 月 6 日
Impossible to say what's wrong until you show us the relevant lines of code where you call those two functions. For example, how do we know that you passed in the correct handles?
Hamza
Hamza 2016 年 3 月 6 日
if true
function results_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to results (see VARARGIN)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
a= getappdata(0,'a');
b=getappdata(0,'b');
d=zeros(size(a,1),size(b,2));
set(handles.uitable1,'Data',d)
choice=getappdata(0,'choice');
switch choice
case 1
if size(a)==size(b)
r=a+b;
set(handles.uitable1,'Data',r)
else
set(handles.text1,'string','lenghts must agree')
end
case 2
if size(a)==size(b)
r=a-b;
set(handles.uitable1,'Data',r)
else
set(handles.text1,'string','lenghts must agree')
end
case 3
if size(a,2)==size(b,1)
r=a*b;
set(handles.uitable1,'Data',r)
else
set(handles.text1,'string','inner dimensions must agree')
end
case 4
set(handles.uitable1,'Data',inv(a))
case 5
end
end
Hamza
Hamza 2016 年 3 月 7 日
where are you?
Geoff Hayes
Geoff Hayes 2016 年 3 月 7 日
編集済み: Geoff Hayes 2016 年 3 月 7 日
Hamza - as Image Analyst commented, it isn't clear from within your code where or how the two GUIs are tied together. Which line of code is generating the error? Is the uitable1 part of your results GUI? Please don't copy and paste the same body of code (again). Just include the relevant lines of code that generate the error and/or link the two GUIs.
Hamza
Hamza 2016 年 3 月 7 日
This code taken from second GUI Yes the error is in uitable part
Geoff Hayes
Geoff Hayes 2016 年 3 月 7 日
Hamza - which line of code is generating the error? Are you sure that uitable1 exists in the second GUI? Put a breakpoint at
choice=getappdata(0,'choice');
and run your code. When the debugger pauses at this line, look at the handles structure. Is there a field called uitable1?
Also, what is your work flow. Do you launch the first GUI and do some work, and then manually launch the second GUI? Please describe the steps.
Hamza
Hamza 2016 年 3 月 7 日
編集済み: Hamza 2016 年 3 月 7 日
The error when I set data to table Yes I am sure uitable is exist My workflow is I push button in gui 1 then gui2 pop up and store data taken from gui1 in gui2
Geoff Hayes
Geoff Hayes 2016 年 3 月 7 日
And what happens when you put a breakpoint at the line I mentioned? Please try that and verify uitable1 exists. Else post the m and fig files for your GUI so that we can verify that it is correct.
Hamza
Hamza 2016 年 3 月 7 日
the error begins from here set(handles.uitable1,'Data',d)
Geoff Hayes
Geoff Hayes 2016 年 3 月 7 日
So given the error message, handles does not have a field named uitable1. Can you post your m and fig files so that we can verify whether or not this control exists in the results GUI?
Image Analyst
Image Analyst 2016 年 3 月 7 日
And, by the way, you missspelled lengths as lenghts.
Hamza
Hamza 2016 年 3 月 7 日
you are right i have uitable2 in my gui not uitable1 thank you very much it works fine

サインインしてコメントする。

 採用された回答

Geoff Hayes
Geoff Hayes 2016 年 3 月 7 日

0 投票

Hamza - if you look at your results.fig from within GUIDE, you will note that there is one uitable and one static text control. If you double-click on the uitable and look at its Tag property you will see that it is named uitable2 and not uitable1. Change the name, save the figure/GUI, and try again.

1 件のコメント

Hamza
Hamza 2016 年 3 月 7 日
thank you the tag was uitable2 not uitable1 now it works fine

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2016 年 3 月 6 日

コメント済み:

2016 年 3 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by