如何重新排序Listbox数据?
2个视图(过去30天)
显示旧注释
我已经创建了GUI:
- ListBox创建,并在matlab中向上移动按钮为'。它起作用了
代码:
函数moveUp (src、事件lbox)
index_move = ismember(1:length(lbox.Items),lbox.Value);
Index_shift = circshift(index_move,-1);
position = 1:length(lbox.Items);
如果isequal (lbox.Value, 1)
Position = circshift(Position,-1);
其他的
Value_up = position(index_move);
Value_down = position(index_shift);
Position (index_shift) = value_up;
Position (index_move) = value_down;
结束
集(lbox,‘物品’,lbox.Items(位置);
集(lbox,“价值”,找到(index_shift));
结束
- 但同样的代码在Matlab应用程序设计器中无法工作
代码:
index_move = ismember(1:length(app.ListBox.Items), size(app.ListBox.Value));
Index_shift = circshift(index_move,-1);
position = 1:length(app.ListBox.Items);
如果isequal (app.ListBox.Value, 1)
Position = circshift(Position,-1);
其他的
Value_up = position(index_move);
Value_down = position(index_shift);
Position (index_shift) = value_up;
Position (index_move) = value_down;
结束
集(app.ListBox.Items app.ListBox.Items(位置);
集(app.ListBox.Value,找到(index_shift));
请给我提个建议。
0评论
接受的答案
凯文·霍利
2022年7月7日
下面的代码作为我的回调函数。
index_move = ismember(app.ListBox. ismember)项目,app.ListBox.Value);
Index_shift = circshift(index_move,-1);
position = 1:length(app.ListBox.Items);
如果isequal (app.ListBox.Value, 1)
Position = circshift(Position,-1);
其他的
Value_up = position(index_move);
Value_down = position(index_shift);
Position (index_shift) = value_up;
Position (index_move) = value_down;
结束
集(应用程序。列表框,“项目”app.ListBox.Items(位置));
集(应用程序。列表框,“价值”app.ListBox.Items(找到(index_shift)));