2011-06-22 89 views
0

裏面我設計一個GUI,我試圖加載從結構的墊子文件轉換成一個結構,然後訪問數據。我也想打印結構中的變量來查看變量是否在mat文件中,並且它們工作。謝謝,我也沒有太多的matlab經驗。這裏是我的代碼:MATLAB裝載.MAT文件和訪問變量結構

function pushbutton5_Callback(hObject, eventdata, handles) 
%get path 
[FileName,PathName] = uigetfile('*.mat','Select mat file'); 

if (FileName==0) %cancel is pressed 
    return; 
end 

Struct1 = load('FileName'); 
Structname = fieldnames(Sruct1); 


MatDef = [PathName FileName]; %path and name 
set(handles.edit2,'String',MatDef) %shows directory string 

現在我收到錯誤,試圖加載mat文件到結構中。

回答

0

嘗試更換以下:

[FileName,PathName] = uigetfile('*.mat','Select mat file'); 
if FileName==0, return, end 

Struct1 = load(fullfile(PathName,FileName)); %# pass file path as string 
Structname = fieldnames(Struct1);    %# typo? 
+0

感謝,真正幫助 – Khoa