Saving Items Different listbox in a text file (App designer)

2 次查看(过去 30 天)
It's the first time i'm using app designer i'm trying to save the items of different Listbox in one file.txt
I report the code of the list box.
The structure of the file should be "
Firstlist:
Item=Itemdata
Item1=ItemData1
Secondlist:
Itemsecondlist=Itemdatasecondlist
Thirdlist:
Itemthitdlist=Itemdatathirdlist
.."
function AddButtonPushed(app, event)
%when the Addbutton is pushed the listbox is filled with the
%string written in the editfield and a code is associated in
%the ItemsDAta
app.ComandiListBox.Items = [string(app.ComandiListBox.Items),string(app.aggiungiEditField.Value)];
app.ComandiListBox.ItemsData = [app.ComandiListBox.ItemsData, app.codiceEditField.Value];
end
%I've tried something like that for the first listbox but isn't working
function SaveButtonPushed(app, event)
C=num2cell(app.ComandiListBox.ItemsData);
C2=[app.ComandiListBox.Items; C];
fileID = fopen('prova1.txt','w');
formatSpec = '%s=%d\n';
[nrows,ncols] = size(C2);
for row = 1:nrows
fprintf(fileID,formatSpec,C2{row,:});
end
fclose(fileID);
end

回答(1 个)

Abhilash Padma
Abhilash Padma 2019-12-31
If you want to save the items of a list box when selected, you can use the ‘’ValueChangedFcn” callback of list box to save the items in a text file. See the code below where I have used a list box in my app with different values and saving the value when selected:
function cityListBoxValueChanged(app, event)
value = app.cityListBox.Value;
fileID = fopen('example2.txt','w');
fprintf(fileID,'%s = %s','val1',value);
end

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by