How to pass variabel itu m file from GUI to another m file (not GUI)

1 回表示 (過去 30 日間)
ciptya almira
ciptya almira 2017 年 6 月 19 日
コメント済み: ciptya almira 2017 年 6 月 19 日
i have a source code like this
function genfis_Callback(hObject, eventdata, handles)
% hObject handle to genfis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
klas = str2num(get(handles.klas,'String'));
handles.klas = klas;
guidata(hObject,handles);
dataku = handles.data;
[n, m] = size(dataku); %ambil dari load data, gmn?
A = dataku(:,1:m-1);
handles.A = A;
guidata(hObject,handles);
[center,U,obj_fcn] = fcm(A,klas);
maxU = max(U);
[Yy,Li] = max(U)
handles.fcmout = [Yy,Li];
guidata(hObject,handles);
and i want to pass handles.fcmout to another m.file (not GUI)
this is an anothe m.file
function [a,c,U,obj_fcn] = findDevMean(A,klas);
handles = guidata(hObject);
[n,m] = size(A);
[Yy,Li] = handles.fcmout;
and the are some error like this
Undefined function or variable 'hObject'.
Error in ==> findDevMean at 2
handles = guidata(hObject);
how can i do fix this problem?
thank you for your helping
  2 件のコメント
Adam
Adam 2017 年 6 月 19 日
You haven't shown the code where you are calling findDevMean.
What is wrong with just passing it in:
[a,c,U,obj_fcn] = findDevMean(A,klas,handles.fcmout);
?
Then define the function simply as:
function [a,c,U,obj_fcn] = findDevMean(A,klas,fcmout);
[n,m] = size(A);
[Yy,Li] = fcmout;
Don't mix up GUI handles in a function that has nothing to do with a GUI, just pass the data itself.
Walter Roberson
Walter Roberson 2017 年 6 月 19 日
編集済み: Walter Roberson 2017 年 6 月 19 日
Note that fcmout is a vector of two elements, and that you cannot split a vector using [Yy,Li] = fcmout syntax.
Atch, it isn't a vector, it is formed from the two-output version of max() applied to a 2D matrix, so it is two row vectors being spliced together. Sure would be easier if it were being saved a different way, like
handles.fcmout = {Yy,Li};

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 6 月 19 日
編集済み: Walter Roberson 2017 年 6 月 19 日
Change
function [a,c,U,obj_fcn] = findDevMean(A,klas);
handles = guidata(hObject);
[n,m] = size(A);
[Yy,Li] = handles.fcmout;
to
function [a,c,U,obj_fcn] = findDevMean(A,klas);
[n,m] = size(A);
handles = guidata( findobj(0, 'tag', 'gensis') );
fcmout = handles.fcmout;
Yy = fcmout(1:end/2); Li = fcmout(end/2+1:end);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by