필터 지우기
필터 지우기

Gui table with dropdown problem

조회 수: 7 (최근 30일)
Baha411
Baha411 2019년 7월 29일
댓글: Baha411 2019년 7월 31일
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.

답변 (1개)

Jalaj Gambhir
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
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.
Baha411
Baha411 2019년 7월 31일
Thanks!
Quick questions... Is this suggesting that the App Designer is better and more advanced? Do you know limitations of each of these options? And is App Designer suggesting that Guide may be removed in future?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by