Gui table with dropdown problem
2 次查看(过去 30 天)
显示 更早的评论
Hi! I am trying to create a GUI with table that includes first column with a dropdown list in each cell. But I keep getting an error. The opening fuction for the uitable is below:
% --- Executes just before GuiTable01 is made visible.
function GuiTable01_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GuiTable01 (see VARARGIN)
% Choose default command line output for GuiTable01
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
Nrows = 40; Ncols = 6;
Data_init0 = cell(Nrows,Ncols);
set(handles.uitable1,'Data',Data_init0); % this creates an empty table
% to create a table with dropdown
Ndropdown = 4;
dropdown = categorical(ones(Nrows,1),1:Ndropdown,{'Select','HorLayer','VerLayer','Point'});
emp = cell(Nrows,0); % empty cells
tdata = table(dropdown,emp,emp,emp,emp,emp,'VariableNames',{'c1','c2','c3','c4','c5','c6'});
set(handles.uitable1,'Data',tdata);
This gives an error message "Error using matlab.ui.control.Table/set
Functionality not supported with figures created with the figure function. For more information, see Graphics Support in App Designer."
However, this is what I am trying to do:
Ndropdown = 4; Nrows = 40;
dropdown = categorical(ones(Nrows,1),1:Ndropdown,{'Select','HorLayer','VerLayer','Point'});
emp = cell(Nrows,0); % empty cells
tdata = table(dropdown,emp,emp,emp,emp,emp,'VariableNames',{'c1','c2','c3','c4','c5','c6'});
fig0 = uifigure; uit = uitable(fig0,'Data',tdata,'ColumnEditable',true);
I appreciate any ideas to fix the code or if there is any other ideas to do what I am trying to do.
0 个评论
回答(1 个)
Jalaj Gambhir
2019-7-31
Hi,
Unfortunately, this functionality is not available in GUIDE. You can do the same in App Designer by using this code in the startupFcn callback:
Nrows = 40; Ncols = 6;
Data_init0 = cell(Nrows,Ncols);
app.UITable.Data = Data_init0; % this creates an empty table
% to create a table with dropdown
Ndropdown = 4;
dropdown = categorical(ones(Nrows,1),1:Ndropdown,{'Select','HorLayer','VerLayer','Point'});
emp = cell(Nrows,0); % empty cells
newDisplayData = table(dropdown,emp,emp,emp,emp,emp,'VariableNames',{'c1','c2','c3','c4','c5','c6'});
app.UITable.Data = newDisplayData;
app.UITable.ColumnEditable = true;
3 个评论
Jalaj Gambhir
2019-7-31
Hi,
App Designer and GUIDE are two different methods of creating graphic applications in MATLAB. App Designer provides an enhanced UI component set and design environment. You can know more here.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!