MATLAB App Listbox items not changing

조회 수: 2 (최근 30일)
Pablo Rodríguez Suárez
Pablo Rodríguez Suárez 2022년 2월 19일
댓글: Pablo Rodríguez Suárez 2022년 2월 20일
I am trying to modify the default values of a listbox in a Matlab App (Item 1, Item 2...) by using the following code:
value = app.CountryListBox.Value; %Default value that appears when I created a callback for the listbox
first_cell_column=covid_data(:,1); %Extract the first column of my cell array, which contains the name of the countries
first_unique_column=unique(first_cell_column); %Remove repeated names
countries=(first_unique_column(first_unique_column~="Country")).'; %Remove the tag "country" and transpose my column vector to a row vector (1x195)
app.CountryListBox.Items=countries; %Assign my cell row vector to the CountryListBox Items object
However, when I run the app, the Listbox remains unchanged, with the same default values. No error or warning appears on the program neither. What am I doing wrong?

답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 2월 19일
편집: Cris LaPierre 2022년 2월 19일
Where have you placed the code in your app? It appears to be in your listbox ValueChanged callback. That means this function will not execute until you select a different item in your listbox.
Try selecting item2 or item3. Your listbox should update. Or at least this callback funciton will execute.
  댓글 수: 2
Pablo Rodríguez Suárez
Pablo Rodríguez Suárez 2022년 2월 20일
It appeared automatically here:
% Value changed function: CountryListBox
function CountryListBoxValueChanged(app, event)
first_cell_column=covid_data(:,1);
first_unique_column=unique(first_cell_column);
countries=(first_unique_column(first_unique_column~="Country")).';
app.CountryListBoxValueChanged.Items={'countries'};
Right after the StartUpFcn. How do I select item 2 or 3?
Pablo Rodríguez Suárez
Pablo Rodríguez Suárez 2022년 2월 20일
Ok, it's solved! I put the exact same code on the StartUp function, and it worked. Now I understand what you mean by selecting the second item...Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by