2012-10-15 55 views
0

使用一套我曾嘗試下面的代碼在Matlab:錯誤在MATLAB中,而在GUI

function pushbutton5_Callback(hObject, eventdata, handles) 

global smoothening_level; 

global Amp_threshold; 

global Min_PeakDistance; 

global Mat_wave 

global Mat_wave2 

global Mat_inten 

global pks 

Mat_inten2 = smooth(Mat_inten,smoothening_level); 

[pks,locs] = findpeaks(Mat_inten2,'minpeakdistance',Min_PeakDistance,'minpeakheight',Amp_threshold) 

s = size(pks) 

figure(1) 

Mat_wave2 = Mat_wave(locs(:)); 

Mat_inten2loc = Mat_inten(locs(:)); 

hold all; 

plot(Mat_wave,Mat_inten2); 

plot(Mat_wave2,pks,'o','MarkerEdgeColor','r'); 

legend('Ouptut Spectrum','Smoothened Spectrum','Identified Peaks') 

axis([350 900 0 max(Mat_inten)]); 

xlabel('Wavelength') 

ylabel('Intensity') 

grid on 

title('Plasma Emission Spectrum') 

temp(:,1)=Mat_wave2; 

temp(:,2)=Mat_inten2loc; 

set(handles.uitable8,'Data',num2cell(temp)) 

但是它給了以下錯誤:

??? Attempt to reference field of non-structure array. 

Error in ==> GUI>pushbutton5_Callback at 242 
set(handles.uitable8,'Data',num2cell(temp)) 

Error in ==> gui_mainfcn at 96 
     feval(varargin{:}); 

Error in ==> GUI at 50 
    gui_mainfcn(gui_State, varargin{:}); 

Error in ==> @(hObject,eventdata)GUI('pushbutton5_Callback',hObject,eventdata,guidata(hObject)) 

??? Error while evaluating uicontrol Callback 

回答

1

該錯誤告訴您,handles不是struct類型。因此,您不能訪問handles.uitables8。最有可能你想寫的是 set(handles,'Data',num2cell(temp))',但這只是一個猜測而不知道你的代碼的其餘部分。

0

檢查,以確保手柄。 uitable8存在。最簡單的方法是在第242行的代碼中設置一個斷點。當代碼在調試器中停止時,轉到工作區並打開句柄結構。

如果您使用GUIDE創建了這個gui,那麼很可能該標籤會被誤標或類似。