Help me please: Problem to compare elements in array with its label using grp2idx and grpstats
Show older comments
My problem is stated above.I have done trouble shooting and turned out these comparison is evaluated to false, thus I cannot count the occurences.
if((grp1(counting)== g1{ixx}) && (grp2(counting) == g2{ix}))
Is there any other way to compare them as I have tried using isequal function.Besides the coding seems logic to me.
grp1, grp2 are instances frm f1 and f2 respectively after using grp2idx function
g1,g2 are labels name frm f1,f2 respectively after using grpstats function.
e.g. the coding is to count occurences of instances of 1st label of g1 in grp1 given it is the 1st label of g2 in grp2;smthg to do with probability.
Thank you.
transportA data
1 10
1 11
0 11
0 10
1 11
1 10
0 11
0 11
1 12
0 12
load transportA
A=dataset(transportA);
[nobs,nvars] = getsize(A);
BB = A(:,1);
disp(BB);
grp1=grp2idx(BB);
disp('group1 = ');disp(grp1);
ct1=max(grp1);disp('qty grp1 = ');disp(ct1);
[g1,num1]=grpstats(grp2idx(BB),grp1,{'gname','numel'});
disp('g1 = ');disp(g1);
disp('num1 = ');disp(num1);
DD = A(:,2);
disp(DD);
grp2=grp2idx(DD);
disp('group2 = ');disp(grp2);
ct2=max(grp2);
disp('qty grp2 = ');disp(ct2);
[g2,num2]=grpstats(grp2idx(DD),grp2,{'gname','numel'});
disp('g2 = ');disp(g2);
disp('num2 = ');disp(num2);
for ix = 1 : ct2
for ixx = 1 : ct1
count = 0 ;
label1 = g1{ixx};
label2 = g2{ix};
disp('label1 = ');disp(label1);
disp('label2 = ');disp(label2);
for counting = 1 : nobs
oblong1 = grp1(counting);disp('oblong1 = ');disp(oblong1);
oblong2 = grp2(counting);disp('oblong2 = ');disp(oblong2);
%tf=isequal(grp1(counting),g1{ixx});disp('tf=');disp(tf);
if(grp1(counting)== g1{ixx}) && (grp2(counting) == g2{ix})
count = count + 1;
end
end
disp('count = ');disp(count);
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Correlation and Convolution 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!