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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by