Add a new item to existing list and save it and Dot indexing is not supported for variables of this type
2 views (last 30 days)
Show older comments
Hi,
I am developping an app for EV's. i am looking for a way to allow the future users to add new vehicles to the drop down menu. To do this, i need a code to modify the existing item list, and add new EVs referances. I found this code, i modified a bit and it somehow works
However ! when i close the app the name desepears, and i have to start again. What i am i missing ?, and how to make the code saves the new car, in the existing database without deleting it after restart
thank you
new_car = "WhatEver";
app.VehicleModelDropDown.Items = [app.VehicleModelDropDown.Items new_car];
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/353822/image.jpeg)
0 Comments
Answers (1)
Mohammad Sami
on 31 Aug 2020
You need to load and save Items from a .mat file if you wish your changes to be persisted across runs. Otherwise the items will always initialise to the values you have coded in your app.
3 Comments
Mohammad Sami
on 31 Aug 2020
Add a startupFcn to your app. This can be done by going into the code view and clicking App Input Arguments.
It will open a dialog, type "varargin" and click ok. It will create the startupFcn.
% Code that executes after component creation
function startupFcn(app, varargin)
list = load('VehicleList.mat');
app.VehicleModelDropDown.Items = list.VehicleList;
end
function UpdateVehicleList(app,new_car)
VehicleList = [app.VehicleModelDropDown.Items new_car];
save('VehicleList.mat','VehicleList','-append');
app.VehicleModelDropDown.Items = VehicleList;
end
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!