I have two set of data (each 1000 numbers), A and B. Each number of A has a specific value in B (A(i,1)=B(i,1)). for example:
A=[ 1 ; 2 ; 1 ; 5 ; 10 ; 5 ]B=[0.1 ; 0.5 ; 0.2 ; 0.3; 0.8 ; 0.9]
For A=1, B=0.1 & 0.2 >>>> so when A=1, B=0.3 (sum of the values) For A=2, B=0.5 >>>> so when A=2, B=0.5 Some of A values are repeated. I want to sum the repeated values of A for each value of B and then plot A Vs B. The following code has been used to calculate the summation:
[uA a b] = unique(A); sB = arrayfun(@(x) (sum(B(b==x))), 1:numel(a)); X = [uA sB'];
This method works perfectly, but when I want to plot uA Vs sB, it gives me a very bad curve. The problem is that 1000 close data, sB does not give me the best answer because the uA has downward/upward/downward trend (comes from a set of data).for example at x=45 (attached file), I should have 4 different values for y and sum them up and get around y=11, but my data has only two values of exact 45 and the next close numbers are 44 and 46. therefore by using above method at uA=45, sB=5.6 which is incorrect (instead of 11).
please find attached file.
In summary, as shown in attached file, from x=0 to x=250, y has 2,3 or 4 values. for example, exact x=20 there might be 1,2,3 or 4, values.
I was wondering how to solve that problem ,is using average or median a good idea?
Best Answer