forked from sharktank-bic/qMTLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreorderTable.m
96 lines (78 loc) · 2.64 KB
/
reorderTable.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function ordered = reorderTable(filenames)
scrsz = get(0,'ScreenSize');
h(1) = figure('position', [1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2]);
h(2) = uitable(h(1),...
'data' , filenames, ...
'ColumnName','Filenames', ...
'ColumnWidth', {floor(scrsz(3)/100)*25} , ...
'units' , 'normalized',...
'position', [0.1 0.1 0.6 0.85],...
'CellSelectionCallback', @selectCells);
h(3) = uicontrol(...
'style' , 'pushbutton', ...
'units' , 'normalized',...
'position', [0.75 0.6 0.2 0.15],...
'string' , 'Up',...
'callback', @reOrder);
h(4) = uicontrol(...
'style' , 'pushbutton', ...
'units' , 'normalized',...
'position', [0.75 0.4 0.2 0.15],...
'string' , 'Down',...
'callback', @reOrder);
h(5) = uicontrol(...
'style' , 'pushbutton', ...
'units' , 'normalized',...
'position', [0.75 0.2 0.2 0.15],...
'string' , 'Done',...
'callback', @orderDone);
set(h(3:4), 'enable', 'off');
uiwait;
ordered = get(h(2),'Data');
close(h(1));
function selectCells(src, evt)
if ~isempty(evt.Indices)
set(src, 'UserData', evt.Indices);
set(h(3:4), 'enable', 'on');
else
% set(h(3:4), 'enable', 'off');
end
end
function reOrder(src,~)
button = get(src, 'string');
table = h(2);
data = get(table, 'Data');
selected = get(table, 'UserData');
selected = selected(:,1);
switch button
case 'Up'
sel = selected-1;
not_selected = setdiff(sel, selected);
nsel = setdiff(selected, sel);
if sel(1)>=1 && nsel(end)<=size(data,1)
new_data = data;
new_data(sel ,:) = data(selected,:);
new_data(nsel,:) = data(not_selected,:);
else
return
end
case 'Down'
sel = selected+1;
not_selected = setdiff(sel, selected);
nsel = setdiff(selected, sel);
if sel(1)<=size(data,1) && nsel(end)>=1
new_data = data;
new_data(sel ,:) = data(selected,:);
new_data(nsel,:) = data(not_selected,:);
else
return
end
end
set(table, 'Data', new_data);
% set(h(3:4), 'enable', 'on');
set(table, 'UserData',sel)
end
function orderDone(src,evt)
uiresume;
end
end