Insert an element once in a listbox

1 回表示 (過去 30 日間)
Samah EL QASSAH
Samah EL QASSAH 2017 年 11 月 27 日
コメント済み: KL 2017 年 11 月 27 日
I wrote the following code that allows me to insert the word "Cab1" in a list once the condition is true
if (Output == 1)
str = get(handles.list_Update, 'string');
str = cellstr(str);
str{end+1} = 'Cab1';
set(handles.list_Update, 'String', str);
end
But I get the result below because the condition "Output = 1" is still true. I want to insert the word "Cab1" only once in the list even if Output remains at 1. Can a Brake help me to solve the problem otherwise how to do it?

回答 (1 件)

KL
KL 2017 年 11 月 27 日
Check if your string already existing in your listbox and make output false in that case?
Something like,
if (Output == 1)
str = get(handles.list_Update, 'string');
str = cellstr(str);
if find(ismember(str, 'cab1'))
output = 0;
else
str{end+1} = 'Cab1';
set(handles.list_Update, 'String', str);
end
end
  2 件のコメント
Samah EL QASSAH
Samah EL QASSAH 2017 年 11 月 27 日
Thanks KL for the help, yes, but I don't want to set the "Output" to 0
KL
KL 2017 年 11 月 27 日
If you don't want to set the output to be zero, you can do nothing under the true case and simply return to your main routine.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by