How to reorder the Listbox data ?
3 ビュー (過去 30 日間)
古いコメントを表示
I have created GUI:
- ListBox created, and Move up button in matlab as '.m' it is working
Code:
function moveUp(src,event,lbox)
index_move = ismember(1:length(lbox.Items),lbox.Value);
index_shift = circshift(index_move,-1);
position = 1:length(lbox.Items);
if isequal(lbox.Value,1)
position = circshift(position,-1);
else
value_up = position(index_move);
value_down = position(index_shift);
position(index_shift) = value_up;
position(index_move) = value_down;
end
set(lbox,'Items',lbox.Items(position));
set(lbox,'Value',find(index_shift));
end
- But the same code is not working in Matlab app designer
Code:
index_move = ismember(1:length(app.ListBox.Items), size(app.ListBox.Value));
index_shift = circshift(index_move,-1);
position = 1:length(app.ListBox.Items);
if isequal(app.ListBox.Value,1)
position = circshift(position,-1);
else
value_up = position(index_move);
value_down = position(index_shift);
position(index_shift) = value_up;
position(index_move) = value_down;
end
set(app.ListBox.Items,app.ListBox.Items(position));
set(app.ListBox.Value,find(index_shift));
Kindly suggest a way for this?
0 件のコメント
採用された回答
Kevin Holly
2022 年 7 月 7 日
The following code worked as a callback function for me.
index_move = ismember(app.ListBox.Items, app.ListBox.Value);
index_shift = circshift(index_move,-1);
position = 1:length(app.ListBox.Items);
if isequal(app.ListBox.Value,1)
position = circshift(position,-1);
else
value_up = position(index_move);
value_down = position(index_shift);
position(index_shift) = value_up;
position(index_move) = value_down;
end
set(app.ListBox,'Items',app.ListBox.Items(position));
set(app.ListBox,'Value',app.ListBox.Items(find(index_shift)));
10 件のコメント
Kevin Holly
2022 年 7 月 14 日
If you are using the function in both apps, I would suggest saving the function as a file that is called from each app. You can change the input to the function based on what app you call from (e.g. updateRunOrder(app,orderconnection,newnames) or updateRunOrder(app.Callingapp,orderconnection,newnames)).
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!