如何重新排序Listbox数据?

2个视图(过去30天)
Lavanya
Lavanya 2022年7月7日
评论道: 凯文·霍利 2022年7月14日
我已经创建了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));
请给我提个建议。

接受的答案

凯文·霍利
凯文·霍利 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)));
10评论
凯文·霍利
凯文·霍利 2022年7月14日
如果你在两个应用程序中使用该函数,我建议将该函数保存为从每个应用程序调用的文件。你可以根据你从什么应用程序调用(例如updateRunOrder(app,orderconnection,newnames)或updateRunOrder(app. callingapp,orderconnection,newnames)来更改函数的输入。

登录发表评论。

更多答案(0)

社区寻宝

在MATLAB中央找到宝藏,并发现社区可以如何帮助你!

开始狩猎!

翻译的