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

1 vue (au cours des 30 derniers jours)
ciptya almira
ciptya almira le 19 Juin 2017
Commenté : ciptya almira le 19 Juin 2017
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 commentaires
Adam
Adam le 19 Juin 2017
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 le 19 Juin 2017
Modifié(e) : Walter Roberson le 19 Juin 2017
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};

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 19 Juin 2017
Modifié(e) : Walter Roberson le 19 Juin 2017
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);

Plus de réponses (0)

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by