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
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!