Adding and Deleting Columns in UITable App Designer
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ratanjot
el 21 de Feb. de 2023
Comentada: Ratanjot
el 23 de Feb. de 2023
I have created an example app with app designer where it will output the data from the excel sheet with the UITable. The user must have the ability to delete columns 4-8 via the clicking on the checkbox and then also add them back to there respected locations in the Table as it was originally. For example, the user should be able to uncheck columns 4 and 6, which will delete the column name and the data for those columns out of the table and only display columns 1-3,5,7-13.
The problem I am having is that upon deleting the column such as column 4, it doesn't delete the specified column name, but rather the one at the very end (i.e., column 13) and the data for column 4. From there, all the data from the right side of column 4 from the original table will shift one to the left. The solution here would be so that column 4 variable name and data are deleted but the rest is kept in the table. If the user decides to put the column back in the table, it will simply be by checking the same checkbox and it will come back to where it once was. For example, if column 4 was deleted by unchecking the checkbox, then later on checked, it will return as the fourth column in the table and not at the very end like how I have it in the code currently. Thank you for your help.
0 comentarios
Respuesta aceptada
VBBV
el 22 de Feb. de 2023
Editada: VBBV
el 22 de Feb. de 2023
You can modify the function for columnCheckBox Value Changed as below, by using addvars function
function Column4CheckBoxValueChanged(app, event)
value = app.Column4CheckBox.Value;
if value == 0
app.t_final = removevars(app.UITable.Data,4);
app.t_final.Properties.VariableNames = ["One","Two","Three","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen"];
app.UITable.ColumnName = app.t_final.Properties.VariableNames;
app.UITable.Data = (app.t_final)
elseif value == 1
app.t_final = addvars(app.UITable.Data,table2array(app.t_4),'After','Three');
app.t_final.Properties.VariableNames = ["One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen"];
app.UITable.ColumnName = app.t_final.Properties.VariableNames;
app.UITable.Data = app.t_final;
end
end
7 comentarios
VBBV
el 23 de Feb. de 2023
Anyways, your question was related to adding and deleting the data to table in App using checkboxes. Please open a new question, if you have further questions
Más respuestas (1)
Simon Chan
el 23 de Feb. de 2023
Attached is another apporach for your reference.
The modification includes the followings:
(1) Save the original table in the 'UserData' of the uitable.
app.UITable.UserData = app.UITable.Data;
(2) Assign the column number to 'Tag' of the checkbox for that column. Such as 5 for app.Column5CheckBox
(3) The callback for each checkbox would be almost the same except the name of the checkbox.
The following shows the callback for Column4CheckBox and Column5CheckBox as an example.
% Value changed function: Column4CheckBox
function Column4CheckBoxValueChanged(app, event)
value = app.Column4CheckBox.Value;
idx = ismember(["One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen"],app.UITable.ColumnName);
idx(str2double(app.Column4CheckBox.Tag))=~value;
app.UITable.ColumnName = app.UITable.UserData.Properties.VariableNames(idx);
app.UITable.Data = app.UITable.UserData(:,idx);
end
% Value changed function: Column5CheckBox
function Column5CheckBoxValueChanged(app, event)
value = app.Column5CheckBox.Value;
idx = ismember(["One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen"],app.UITable.ColumnName);
idx(str2double(app.Column5CheckBox.Tag))=~value;
app.UITable.ColumnName = app.UITable.UserData.Properties.VariableNames(idx);
app.UITable.Data = app.UITable.UserData(:,idx);
end
On the other hand, I set all checkboxes to false when the program start.
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!