필터 지우기
필터 지우기

Add a new item to existing list and save it and Dot indexing is not supported for variables of this type

조회 수: 1 (최근 30일)
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];

답변 (1개)

Mohammad Sami
Mohammad Sami 2020년 8월 31일
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
Mohammad Sami
Mohammad Sami 2020년 8월 31일
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
Khalala Mamouri
Khalala Mamouri 2020년 8월 31일
Hi mohammad thanks for the fast replay and code.
Unfortunately i run in some problems using the load function so a changed a bit the code, but still the same idea as yours. So i am using "fopen" instead of "load" and a .m file unstead of .mat. As i said i think the principal is the same for both, how ever, when i start simulation i get this error :
" Dot indexing is not supported for variables of this type "
The code i am using is given bellow.
function startupFcn(app, varargin)
evalin('base', 'clear all')
evalin('base', 'clc')
list = fopen('VehicleList.m','r'); % Read data from the file
A = textscan(list, '%c'); % Importing data
fclose(list); % close file
AB = char(A); % Cell to char conversion
assignin('base','A', A); % send to workspace
assignin('base','AB', AB); % send to workspace
app.VehicleModelDropDown.Items = AB.VehicleList; % << I get the error here
function UpdateVehicleList(app,new_car)
VehicleList = [app.VehicleModelDropDown.Items new_car];
save('VehicleList.m','VehicleList','-append');
app.VehicleModelDropDown.Items = VehicleList;
end
end
Thanks for your time ;)

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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by