[英]Use external function in matlab Gui
我有一个读取2个文件并将它们分配给2个变量的函数:
skelfile='data/name.asf'; %asf and amc files are associated,both needed for later stages
motfile='data/name.amc';
[skel,mot]=readMocap(skelfile,motfile);%the function that i need to use is the readMocap
上面的代码将给变量skel,mot作为1X1结构,同时包含数字和字符信息(包含数字,单元格,字符串,aarays作为结构字段)。
问题是如何在Gui中使用该功能! 我使用一个pusshbutton来加载2个文件并以2个静态文本显示asf,amc文件的文件名asf,amc文件是包含人体骨骼运动捕捉数据的文件,其中asf包含有关骨骼的信息以及有关运动的amc (帧顺序)
function pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to load_MoCap (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.asf', 'MoCap files');
% show name at the static texts
if isequal(filename,0)
set(handles.asf_filename, 'String', 'Please select an .asf file to continue')
else
set(handles.asf_filename, 'String', filename)
skelfile=filename;
[filename2, pathname2] = uigetfile('*.amc;*.c3d', 'MoCap files');
if isequal(filename2,0)
set(handles.amc_filename, 'String', 'Please select an .amc file to continue')
else
set(handles.amc_filename, 'String', filename2)
%the problem
============
%from here i want to run the function and have at a static text the text that
%have when i write skel in the command promt of matlab, or at least somehow
%evaluate tha skel and mot have been assigned as structs
motfile=filename;
[skel,mot]= readMocap(skelfile, motfile);
handles.skel=skel;
handles.mot=mot;
set(handles.skel_mot,'String',skel)
% skel_mot is the static text that refer above
%and i use as property type at the set command th 'string' but i don't think
%that is correct . skel variable is a 1x1 struct
end
end
guidata(hObject,handles);
当您启动空白gui时,代码中除了默认值之外没有其他任何内容。 a)我是否必须在gui的打开功能中添加一些内容(句柄)?我不希望在加载文件之前启动某些内容。 b)我想将文件中的信息用作将要从gui调用的其他函数的输入,因此当我在gui中调用该函数时如何将它们用作输入?如skel,mot或handles.skel, handles.mot ??
预先感谢您的任何答复。
一些东西:
handles
中的字段。 您不需要打开任何文件,只需为它们提供空字符串值或nan值即可。 guidata
函数将数据存储在回调之间的句柄中。 更多信息在这里 。 这样,您可以使用handles.whatever来访问其他回调中的变量。 skel
和mot
是结构。 set(handles.skel_mot,'String',skel)
需要使用skel作为字符串。 我找到了解决问题的方法!
我写了一个脚本,执行我想要的操作。从按钮打开一个窗口以选择我的文件,然后在脚本中调用该函数,以便为结构skel,mot分配所需的信息。 最后,我使用了Molly建议的句柄,还使用了用于在工作区中放置skel,mot的命令assignin。
如此:函数GUI_1_OpeningFcn(hObject,eventdata,句柄,varargin)%默认注释
handles.skel=NaN;
handles.mot=NaN;
% Choose default command line output for GUI_1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
============
more of the default Gui code
============
%pushbutton function
function load_MoCap_Callback(hObject, eventdata, handles)
% hObject handle to load_MoCap (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%callint the script
nameofthescript;
%here skel and mot have been assigned so i put them to the handles
handles.skel=skel;
handles.mot=mot;
%with that i have them at the workspace for evaluation of what i want to do next
assignin ('base', 'skel', handles.skel);
assignin('base','mot',handles.mot);
guidata(hObject,handles);
从那时起,我可以使用handles.skel和handles.mot在我想要的任何其他函数中进行输入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.