Saving Items Different listbox in a text file (App designer)
1 回表示 (過去 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
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!