How to delete the dropdown items permanently using button in app designer
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Harish M Y
 el 5 de Ag. de 2021
  
    
    
    
    
    Comentada: Harish M Y
 el 5 de Ag. de 2021
            Hi,
I am adding items to dropdown using "ADD button", and stroing those values permanently in appdesigner dropdown items.
Like the same way i need to have a "DELETE button" to delete the selected dropdown item permanently. I tried the below code which deletes the selected item successfullt. However if i close and open the app once again, the perviously deleted item is present .
    Properties(access = publix)
        new;
    end
%% .m file to store the dropdown items into the workspace permanently
        dropown = {};
        save('dropdown2.mat' , 'dropdown');
%% Appdesigner code
%% Startup function 
        load('dropdown2.mat');
        app.DropDown.Items  = dropdown;
        %% Add function to add items to dropdown menu and to store those items in dropdown2.mat
        app.new = app.EditField.Value;
        load("dropdown2.mat");
        dropdown(:,end+1) = {app.new};
        save("dropdown2.mat","dropdown","-append");
        app.DropDown.Items = dropdown;
%% Delete button callback function
[~,idx] = ismember(app.DropDown.Value,app.DropDown.Items);
app.DropDown.Items(idx) = [];   %% This delete function call back is deleting the item temporarily. When I re-run the app
%% the deleted item is still present.
%% Please help me to delete the items permanently from dropdown2.mat file also
0 comentarios
Respuesta aceptada
  Rik
      
      
 el 5 de Ag. de 2021
        When you delete an element you need to save the mat file again.
You should also consider loading to a struct instead of poofing the variables in the workspace.
3 comentarios
  Rik
      
      
 el 5 de Ag. de 2021
				You already show you know how to save a mat file, so here is an example of loading to a struct:
S=load("dropdown2.mat");
dropdown=S.dropdown;
This way it is always clear where variables are coming from.
Más respuestas (0)
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!

