MATLAB: Sum an array in one dimension to calculate the probability

indicessum columns

Hi,
I have an array1 (4x3x5) of probabilities. I constructed a second array2 corresponding of probabilities to find some values,for each value in array2 I look in the array1 of probabilies at the same index to know the probability to find the value.
Now the problem is that, in array2, some of the values are duplicated. So first I have to remove all the duplicated values, and to recalculate the probabilities of the new unique values by calculating the sum of the probabilities in the second column where the value is the same in array1.
This is all what I find :
uniqueC = unique(C); to calculate the unique elements of the array. I tried to do manipulations like this : n = histc(C(:), uniqueC, 1);
setdiff(C(:), uniqueC);
But it doesn't work with (4x3x5).
I searched for days before I came here.
Please help me, I need it very soon for an assignement.

Best Answer

Hi.
A(:,:,1) =[0.4528 0.0477 0.0715;0.0220 0.0023 0.0035;0.0045 0.0005 0.0007;0.0511 0.0054 0.0081];
A(:,:,2) =[0.0129 0.0014 0.0020;0.0349 0.0037 0.0055;0.0188 0.0020 0.0030;0.0052 0.0005 0.0008];
A(:,:,3) =[0.0065 0.0007 0.0010;0.0013 0.0001 0.0002;0.0123 0.0013 0.0019;0.0239 0.0025 0.0038];
A(:,:,4) =[0.0194 0.0020 0.0031;0.0078 0.0008 0.0012;0.0446 0.0047 0.0070;0.0427 0.0045 0.0067];
A(:,:,5) =[0.0032 0.0003 0.0005;0.0058 0.0006 0.0009;0.0149 0.0016 0.0023;0.0071 0.0007 0.0011];
C(:,:,1) =[0 25000 35000;20000 45000 55000;
60000 85000 95000;50000 75000 85000];
C(:,:,2) =[15000 40000 50000; 35000 60000 70000
75000 100000 110000; 65000 90000 100000];
C(:,:,3) =[30000 55000 65000;50000 75000 85000
90000 115000 125000;80000 105000 115000];
C(:,:,4) =[75000 100000 110000;95000 120000 130000
135000 160000 170000; 125000 150000 160000];
C(:,:,5) =[5000 30000 40000;25000 50000 60000
65000 90000 100000;55000 80000 90000];
C_1=C(:);
C_2=unique(C_1);
C_3=zeros(size(C_2));
for i=1:length(C_2)
idx=find(C==C_2(i));
C_3(i)=sum(A(idx));
end
C_3