[英]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.