MATLAB Answers

Dot indexing is not supported for variables of this type

30 views (last 30 days)
Khalala Mamouri
Khalala Mamouri on 31 Aug 2020
Commented: Khalala Mamouri on 31 Aug 2020
Hi,
I am developping an app, where i want to load data from a .m fille to fill items for a drop down list. How ever in run into an error "Dot indexing is not supported for variables of this type". Any one knows how to fix this issue ? my code is bellow . Thank you
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

  13 Comments

Mohammad Sami
Mohammad Sami on 31 Aug 2020
Can you amend this part, Also check the txt file has one item per row.
function UpdateVehicleList(app,new_car)
VehicleList = [string(app.VehicleModelDropDown.Items) string(new_car)]';
writematrix(VehicleList,'vehiclelist.txt');
app.VehicleModelDropDown.Items = VehicleList;
end
Mohammad Sami
Mohammad Sami on 31 Aug 2020
Another option can be to use readcell and writecell functions.
function startupFcn(app, varargin)
VehicleList = readcell('vehiclelist.txt');
app.VehicleModelDropDown.Items = VehicleList;
end
function UpdateVehicleList(app,new_car)
VehicleList = [cellstr(app.VehicleModelDropDown.Items) cellstr(new_car)]';
writecell(VehicleList,'vehiclelist.txt');
app.VehicleModelDropDown.Items = VehicleList;
end

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!