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

1 回表示 (過去 30 日間)
Siria Fumagalli
Siria Fumagalli 2019 年 10 月 15 日
回答済み: Abhilash Padma 2019 年 12 月 31 日
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 Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by