필터 지우기
필터 지우기

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

조회 수: 2 (최근 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 CenterFile 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!

Translated by