我是Matlab的新手。我有两个按钮,两个弹出菜单和一个在同一个gui窗口中的uitable。一个按钮用于从Excel工作表导入数据,更新弹出菜单中的列名,另一个按钮用于使用弹出菜单将选定的列数据粘贴到适用的位置。
我已经完成了在弹出菜单中导入数据gui和更新的列名称。我无法通过选择相应的列来粘贴数据。
请在这方面帮助我,我的代码如下,
% --- Executes on button press in pushbuttonLoadData.
function pushbuttonLoadData_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonLoadData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
filename=uigetfile({'*.xls';'*.csv'});
handles.filename=filename;
guidata(hObject, handles);
setpopupmenuString(handles.popupmenuA,eventdata,handles)
setpopupmenuString(handles.popupmenuB,eventdata,handles)
set(handles.popupmenuA,'callback','mainGui(''updateUitable'',hObject,eventdata,g uidata(hObject)')
set(handles.popupmenuB,'callback','mainGui(''updateUitable'',hObject,eventdata,guidata(hObject)')
function setpopupmenuString(hObject,eventdata,handles)
filename=handles.filename;
[numbers,colNames]=xlsread(filename);
set(hObject, 'String', colNames(1,:) );
class(colNames)
size(colNames)
colNames{1,1}
function [x,y] = readExcelcolumns(filename, xColNum,yColNum)
a = xlsread(filename);
x = a (:, xColNum);
y = a (:, yColNum);
[x,y] = readExcelcolumns(filename, xColNum,yColNum)
xColNum(:,2)=importdata('-pastespecial');
yColNum(:,3)=importdata('-pastespecial');
function pushbuttonApply_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonApply (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = handles.filename;
set(handles.uitable1,'Value',xColNum, yColNum);'