我在Matlab中尝试了以下代码:
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
答案 0 :(得分:1)
该错误告诉您handles
不属于struct
类型。因此,您无法访问handles.uitables8
。你最想写的是
set(handles,'Data',num2cell(temp))'
,但这只是猜测而不知道你的其余代码。
答案 1 :(得分:0)
检查以确保handle.uitable8存在。最简单的方法是在第242行的代码中设置断点。当代码在调试器中停止时,转到工作区并打开句柄结构。
如果你使用GUIDE创建了这个gui,那么很可能标签被贴错标签或类似的东西。