-
Notifications
You must be signed in to change notification settings - Fork 8
/
updateMode.m
executable file
·67 lines (62 loc) · 1.98 KB
/
updateMode.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
function updateMode
global NumOfComp NumOfMode Y tdalabStatus;
if isempty(tdalabStatus.inputType)
errordlg('No tensor/ktensor/ttensor found.','No input error','modal');
return;
elseif strcmpi(tdalabStatus.inputType,'tensor')
return;
end
h=findobj('tag','ppMode');
n=get(h,'value');
[s selchn]=selectchn((Y.U{n})');
hrbTucker=findobj('tag','rbTucker');
ind=1:size(Y.U{n},2);
selchn=ind(selchn==1);
if ~isempty(s)
if strcmp(class(s),'double')
s=s';
if strcmp(tdalabStatus.model,'CP')
if size(s,2)~=NumOfComp(1)
errordlg('All the mode matrices must have the same columns in CP model.','Valid selection','modal');
return;
else
Y.U{n}=s;
cleartemp;
end
else % Tucker model
A=Y.U;G=double(Y.core);A{n}=s;
sz=size(Y);
ind=cell(1,NumOfMode);
for i=1:NumOfMode
ind{i}=1:NumOfComp(i);
end
ind{n}=selchn;
G=G(ind{:});
Y=ttensor(tensor(G),A);
cleartemp;
NumOfComp(n)=size(Y.U{n},2);
tdalabStatus.inputType='ttensor';
end
cleartemp;
elseif strcmp(s,'delete')&&NumOfMode>3
if strcmp(tdalabStatus.inputType,'ktensor')
lambda=Y.lambda;A=Y.U;
lambda=lambda(selchn);A=A{selchn};
Y=ktensor(lambda,A);
cleartemp;
elseif strcmp(tdalabStatus.inputType,'ttensor')
G=double(Y.core);G=sum(G,n);G=squeeze(G);A=Y.U;
A(n)=[];
Y=ttensor(tensor(G),A);
cleartemp;
else
errordlg('Unknown error during updating the tensor.','Unknown error','modal');
end
NumOfMode=NumOfMode-1;
NumOfComp(n)=[];
else
errordlg(['Fail to update mode-',num2str(n)],'Update error','modal');
return;
end
updateUI;
end