我有一个Matlab GUI列表框,可以显示文件夹和按钮中的每个文件。如果我选择列表框中显示的文件之一并单击按钮,则该程序应该运行。 这是我的代码:
@NamedQuery(name = "findBookingByVehicle", query = "SELECT c.colour, c.seats, c.make, c.model, b.departureDate, b.returnDate, b.bookingDate, e.fname, e.lname FROM Vehicle c JOIN c.booking b JOIN b.employee e WHERE c = b.vehicle AND b.employee = e ORDER BY b.bookingDate, b.departureDate ")
但是我收到错误未定义的函数或变量' fileselected'。任何的想法?谢谢......
答案 0 :(得分:0)
在函数tab1button_Callback
中,未声明变量fileselected
。
你必须声明fileselected
全局或甚至更好地将它放入handles
结构中,这是所有函数的参数。此结构旨在存储用户数据。
allfiles = dir; %get files
allname = {allfiles(~[allfiles.isdir]).name};
set(handles.wavlist, 'String', allname);
function wavlist_Callback(hObject, eventdata, handles)
filenames = get(hObject, 'String');
filechoice = get(hObject, 'Value');
handles.fileselected = wavnames{filechoice};
function wavlist_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function tab1button_Callback(hObject, eventdata, handles)
[y, fs, nbits, opts] = wavread(handles.fileselected);