Problem with unique command
2 views (last 30 days)
Show older comments
Hello guys. I have a problem with unique command in the following simplified code. The problems are in the 4th iteration as the values of G aren't correct, IC values aren't the repetitions of IA and the resulted Good_path1 isn't a 16*4 matrix. However, the problems are resolved if the position of loops of alpha and beta is changed with the loop of s. Sorry for a lenghy code. I really appreciated if someone help me to solve the problem.
n_c_1=1;
thr_Wght=1e-50;
M=2;
TGponts_1=4;
% &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
K1_1 =[0.0552 - 0.1423i, -0.0145 - 0.1465i, -0.0652 - 0.1285i];
K01_1 = 0.0245 - 0.1175i;
% &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Good_path=[0 0 0 0; 0 0 1 0; 1 0 0 0; 1 0 1 0];
R2=[0.9983 + 0.0000i 0.0047 + 0.0399i 0.0047 - 0.0400i 0.0017 + 0.0000i];
n_c1_1=n_c_1+1; n_c2_1=2*n_c_1;
L_1=2*(n_c1_1);
for n=3:TGponts_1
if n>n_c1_1
Good_path(:,n_c1_1)=[];
Good_path(:,L_1-1)=[];
% Good_path
[Dis_Good_path,IA,IC]=unique(Good_path,'rows','stable');
Dis_R2=zeros(length(IA),1);
for i=1:length(IA)
G=find(IC==IA(i));
G
Dis_R2(i)=sum(R2(G));
end
Good_path=Dis_Good_path
R2=Dis_R2
end
h=size(Good_path);
h1=h(1);
q=0;
nn_1=n-1; nn_2=2*n-2;
s1=M.^2*h1;
if n<=n_c1_1
s2=2*n;
Good_path1=zeros(s1,s2);
else
Good_path1=zeros(s1,L_1);
end
R=zeros(1,s1);
for alpha=0:1
for beta=0:1
for s=1:h1
if (alpha==0 && beta==0) || (alpha==1 && beta==1)
T3=1;
else
Self_int=-(alpha-beta).*(K01_1.*alpha-conj(K01_1).*beta);
%%&&&&&&&&&&&&&&&&&&&&&&&
if n<=n_c1_1
Sum_nlocl_int=0;
for m=n-1:1
a_prim=Good_path(s,m);
b_prim=Good_path(s,n-1+m);
nlocl_int=(K1_1(m).*a_prim-conj(K1_1(m)).*b_prim);
Sum_nlocl_int=Sum_nlocl_int+nlocl_int;
end
else
Sum_nlocl_int=0;
for mm=n_c_1:1
a_prim=Good_path(s,mm);
b_prim=Good_path(s,n_c_1+mm);
nlocl_int=(K1_1(mm).*a_prim-conj(K1_1(mm)).*b_prim);
Sum_nlocl_int=Sum_nlocl_int+nlocl_int;
end
end
Sum_nlocl_int=-(alpha-beta).*Sum_nlocl_int;
T3=exp(Self_int+Sum_nlocl_int);
end
R3=T3*R2(s);
%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
p=abs(R3);
if p>thr_Wght
q=q+1;
if n<=n_c1_1
Good_path1(q,:)=[alpha,Good_path(s,1:nn_1),beta,Good_path(s,n:nn_2)];
else
Good_path1(q,:)=[alpha,Good_path(s,1:n_c_1),beta,Good_path(s,n_c1_1:n_c2_1)];
end
R(q)=R3;
end
end
end
end
%&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Good_path1(q+1:s1,:)=[];
R(q+1:s1)=[];
Good_path=Good_path1
R2=R;
end
2 Comments
Geoff Hayes
on 10 Mar 2019
Davoud - please clarify what you mean by in the 4th iteration as the values of G aren't correct? What are you expecting the values to be?
Accepted Answer
Raghunandan V
on 11 Mar 2019
Hi,
I think there is a confusion between the functions of IA and IC.
lets consider an example
A = [9 2 9 5];
[C, ia, ic] = unique(A,'stable')
the solution is
C = 1×3
9 2 5 (this is the matrix output expected)
ia = 3×1
1 (here 1 refers to the index of the matrix A which is placed in matrix C in index 1)
2 (here 2 refers to the index of the matrix A which is placed in matrix C in index 2)
4 (here 4 refers to the index of the matrix A which is placed in matrix C in index 3)
ic = 4×1
1 (here 1 says that the 1st element of the matrix A is the first element of Matrix C)
2 (here 2 says that the 2nd element of the matrix A is the second element of Matrix C)
1 (here 1 says that the 3rd element of the matrix A is the first element of Matrix C)
3 (here 3 says that the 4th element of the matrix A is the third element of Matrix C)
I am not able to understand what you are doing with the code. The code is very confusing. Please add some comments such that other people can understand.
4 Comments
More Answers (0)
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!