summing tied (duplicate) numbers in a series

1 Ansicht (letzte 30 Tage)
Vincent Odongo
Vincent Odongo am 8 Apr. 2012
Greetings to all, I have a time series data e.g. [4 4 6 7 9 9 9 10 10 13 17 17 17] which is long. I need to identify tied values such that t1=3(three untied values (6, 7, 13)), t2=2 (two ties of extent two (4, 10)), t3=2 (two ties of extent three (9, 17)).
After performing this, I need to sum all the ties in the series using the following equation... ti[(ti-1)(2ti+5)] where ti denotes the magnitude of the tie.
Anyone with suggestion on how to go about this is welcome to help.
Thanks in advance.
Vincent
  1 Kommentar
Sean de Wolski
Sean de Wolski am 10 Apr. 2012
Could you provide the output you expect for the above matrix?
It looks like (histc()||unique)+accumarray() will have a blast with this.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Thomas
Thomas am 10 Apr. 2012
this is a start:
a=[4 4 6 7 9 9 9 10 10 13 17 17 17];
b=unique(a); % this shows unique values
c=find(diff(a)~=0) % finds the differences in the values
d=[0 c length(a)]; % making new matrix to get the values
outputs=sortrows([b' diff(d)'],2)
% follow this by summing your ties..

Andrei Bobrov
Andrei Bobrov am 10 Apr. 2012
t = [4 4 6 7 9 9 9 10 10 13 17 17 17]
[a n n] = unique(t)
m = histc(n,1:max(n))
tout = accumarray(m',a',[],@(x){x})

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by